ghettocounselor
asked on
DECLARE used to define a list
I'm looking to set a list of variables and trying to get the syntax correct
DECLARE @DrugCodes varchar
SET @DrugCodes ???? ('4297','3721','3157')
I'm not sure ???? what to use here to define this?
Thanks
DECLARE @DrugCodes varchar
SET @DrugCodes ???? ('4297','3721','3157')
I'm not sure ???? what to use here to define this?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You may build a dynamic query and execite it.
declare @cmd varchar(200)
set @cmd = 'SELECT * FROM Table WHERE drug_code IN(''4297'',''3721'',''315 7'')'
exec(@cmd)
declare @cmd varchar(200)
set @cmd = 'SELECT * FROM Table WHERE drug_code IN(''4297'',''3721'',''315
exec(@cmd)
I think you should read up this article:
https://www.experts-exchange.com/Database/Miscellaneous/A_1536-delimited-list-as-parameter-what-are-the-options.html
https://www.experts-exchange.com/Database/Miscellaneous/A_1536-delimited-list-as-parameter-what-are-the-options.html
ASKER
so how to use that in a where statement?
I tried
> WHERE drug_code like @DrugCodes
as well as
> WHERE drug_code in @DrugCodes
but neither worked