I’m trying to query a table and get the results into a variable. With the variable results do another select query using the variable details as the filter.
So far:
DECLARE @storeIds int
SET @storeIds = (SELECT StoreID FROM Store WHERE ParentStoreID=9)
--print @storeIds
SELECT c.FirstName, c.LastName, c.CustomerId, r.StoreID
FROM Consumer AS c
INNER JOIN Purchases AS r ON c.CustomerId= r.CustomerId
WHERE r.StoreID = @storeIds
-- (r.StoreID = 9) OR
-- (r.StoreID = 10) OR
-- (r.StoreID = 11)
GROUP BY c.FirstName, c.LastName, c.CustomerId, r.StoreID
ORDER BY c.FirstName
I get an error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Unless you particularly want the
@StoreIdsvariable elsewhere you could just amend yourWHEREclause to: