SQL Distinct keyword in assignment statement
- by Brandi
I have a query that works:
DECLARE @ProductID int
SET @ProductID = '1234'
SELECT DISTINCT TOP 12 a.ProductID
FROM A a
WHERE a.CategoryID IN (SELECT b.CategoryID FROM B b WHERE b.ProductID = @ProductID)
AND a.ProductID != @ProductID
It returns a list of 12 product numbers, all unique.
I need to store these results in a variable, comma…