如何将第一次查询的结果用于第二次查询

时间:2015-10-05 14:56:00

标签: sql-server database

我需要将第一个查询的结果用于第二个查询。

declare @categories tp_intList;
insert into @categories values (1), (2), (3), (4), (5);

select * from product AS prod
inner join 
(
    select MatchedCategoryId from MatchConfigCategories AS dd
    inner join @categories c on c.id = dd.maincategoryid
    inner join (select id from get_AllSubCategories(dd.MatchedCategoryId)) AS cats on prod.shopcatid = cats.id
) AS x on prod.ShopCatid = 4568

我需要将其用于get_AllSubCategories。参数为tp_intList,但我需要来自matchedcategoryid的{​​{1}}。我怎样才能做到这一点? 我有这样的错误

  

多部分标识符

1 个答案:

答案 0 :(得分:0)

DECLARE @cat tp_intList;
INSERT INTO @cat
select ...

this works fine for me