Solved

DECLARE used to define a list

Posted on 2013-01-29
4
147 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 500 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 142

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle query help 18 100
Oracle - Stored Procedure Privilge access 3 41
sql query Help 12 54
SQL Union 20 44
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now