Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

DECLARE used to define a list

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

Question by:ghettocounselor
  • 2

Accepted Solution

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

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

Author Comment

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

Expert Comment

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'')'
LVL 143

Expert Comment

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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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