Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DECLARE used to define a list

Posted on 2013-01-29
4
Medium Priority
?
158 Views
Last Modified: 2013-03-10
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
0
Comment
Question by:ghettocounselor
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
DoutorApedeuta earned 1500 total points
ID: 38831707
Hi, if I understand what you want, try this:

DECLARE @DrugCodes varchar
SET @DrugCodes = '(''4297'',''3721'',''3157'')'
0
 

Author Comment

by:ghettocounselor
ID: 38832037
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
0
 
LVL 1

Expert Comment

by:DoutorApedeuta
ID: 38834798
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)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38835887
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question