Reputation: 3768
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
Upvotes: 0
Views: 85
Reputation: 60190
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
Upvotes: 2