0

my stored proc receive "@CatergoryIDs varchar"

@CatergoryIDs contains single or multiple IDs separated by "|",

my stored proc look like this :

Select R.ID,,CategoryID, (sum(C.Rating)/Count(R.ID)) as "Rating" from Table1 R left outer join Table2 C ON R.ID = C.ID GROUP BY R.ID having R.CategoryID = @CatergoryID RETURN 
1
  • If you're using SQL Server 2008 or above, you should consider using a TVP (Table-Valued Parameter). Commented Apr 22, 2012 at 8:34

1 Answer 1

2

You should be able to use CHARINDEX. However, this is very inefficient, it would be better to have @CategoryID as a table variable.

SET @CatergoryID = '|'+@CatergoryID+'|'; SELECT R.ID, R.CategoryID, (SUM(C.Rating)/COUNT(R.ID)) AS Rating FROM Table1 AS R LEFT OUTER JOIN Table2 AS C ON R.ID = C.ID WHERE CHARINDEX('|'+R.CategoryID+'|', @CatergoryID)>0 GROUP BY R.ID, R.CategoryID 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.