Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Suggestion for replace a function or method

$
0
0
We Have 2 Tables :1- Table Prod2- Table Group>>>>> every Prod May be on one or more GroupsWe have a view that is base of a page with search on fields. In this view we have one Record for every Prod. and we had to collect all Group Id in string Format in a field. that user want search on a group , we show all products on that group. then we have this function for create one field of groups for this view :-----------------------------------------------------------------------------------Create FUNCTION F1 ( @ProdId INT )RETURNS VARCHAR(50)AS BEGIN -- Declare the return variable here DECLARE @strList VARCHAR(50) ='' SELECT @strList = COALESCE(@strList + '|', '') + Convert(varchar(5) ,dbo.Group.id) FROM Group INNER JOIN GroupProduct ON Group.Id = GroupProd.GroupId WHERE GroupProd.ProdId =@ProdId Set @strList=@strList+'|' RETURN @strList END-----------------------------------------------------------Result Prod1 - ... - .... - |54|76|1| - .... > That means Prod1 is on 3 groups : 54 , 76 , 1and we search in this format : where GFiled like '%|76|%'-----------------------------------------------------------Problems :1- Create this Fields has big cost . 2- For search we dont use any index because '%%'is this any idea instead this ?Thank you

Viewing all articles
Browse latest Browse all 3145

Trending Articles