我想查询一个表格并将结果导入变量。使用变量结果做另一个选择使用变量细节作为过滤器的查询。创建一个sql变量并查询其他表格
到目前为止:
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
我得到一个错误:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
比ks巴里!我不知道我可以在WHERE内创建另一个选择语句:( –