Groups | Blog | Home
all groups > sql server data warehouse > february 2006 >

sql server data warehouse : Variable as criteria


Greg
2/7/2006 5:14:27 PM
I would like to reference a variable as the criteria in a query. I want the
criteria to be as follows: in('A','B'). I would assume you set the variable
to equal this but I am doing something wrong

declare @exclusion varchar(255)
set @exclusion = ('A','B','C')

select * from table where code in @exclusion

Any thoughts would be appreciated,

Greg
Aiwa
2/8/2006 6:01:32 AM
Hi Greg,

What you could do is use a table variable to hold your criteria information.

DECLARE @Criteria (CriteriaValue CHAR(1))

INSERT INTO @Criteria VALUES ('A')
INSERT INTO @Criteria VALUES ('B')

SELECT a.*
FROM Table a
JOIN @Criteria b ON b.CriteriaValue = a.code

HTH,
Eric

[quoted text, click to view]
Aiwa
2/8/2006 6:05:30 AM
Sorry there is a typo in my example:

DECLARE @Criteria TABLE (CriteriaValue CHAR(1))


[quoted text, click to view]
AddThis Social Bookmark Button