Solved

DECLARE used to define a list

Posted on 2013-01-29
4
148 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Extract string portion 2 24
SQL Sub-Query Help 22 62
performance query 4 24
Microsoft Access Delete all Records from table but Max 2 11
In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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