Link to home
Start Free TrialLog in
Avatar of ghettocounselor
ghettocounselorFlag for United States of America

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
ASKER CERTIFIED SOLUTION
Avatar of DoutorApedeuta
DoutorApedeuta
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ghettocounselor

ASKER

Ok, that executes.
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
You may build a dynamic query and execite it.

declare @cmd varchar(200)
set @cmd = 'SELECT * FROM Table WHERE drug_code IN(''4297'',''3721'',''3157'')'
exec(@cmd)