简体   繁体   中英

Taking rows from temp-table and using for IN statement

My last post had issues. Alright, I have a temp table that has multiple rows of numbers:

在此处输入图片说明

It gets saved into a table variable:

DECLARE @VALUE varchar(500) = '482';

DECLARE @CONTRACT_MEMBER_BRG_ATTR_ITEM_IDS TABLE
(
   item_id nvarchar(100)
);

INSERT INTO @CONTRACT_MEMBER_BRG_ATTR_ITEM_IDS 
    SELECT item_id 
    FROM [CONTRACT_MEMBER_BRG] 
    WHERE member_item_id = @VALUE 

I need to take all of these values and put it into an in statement in my another query:

SELECT * 
FROM 
    (complicated SELECT query) a
WHERE
    item_id IN (8086, 8087, 8088, 8089, 8090, 8091, 8092);

How would I add all of the rows to a variable that could be used in an IN statement?

... where id in (select id from temp_table where...) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM