How can I make the following sql statement part of the “SET” in my query? I want to pull out a list in a column and have my “SET” run against that. That way my “SET” isn’t just one variable but rather a list to run against. Make sence?
DECLARE @Item as char(32)
declare @result varchar(max);
SET @Item = '034100-3JK';
I want to use something like the following to have it query against instead of the 034100-3JK:
select distinct
a.t_sitm as StartItem
from
ttibom010101 as a
INNER JOIN ttiitm001101 as b on a.t_sitm = b.t_item
where
b.t_ctyp != 'TOP'
and b.t_ctyp != 'SUB'
EDITED: Based on asker’s comments
I noticed that you are explicitly writing out the item code (or ID, whatever you want to call it). If you have a static list of codes that cannot be easily retrieved from your database, you can do something like this:
Alternatively, if that list of codes can be grabbed easily:
Then you can use the variable like a normal table: