|
Home > Archive > MS SQL Data Warehousing > February 2006 > Variable as criteria
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Variable as criteria
|
|
|
| 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
| |
|
| 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
"Greg" wrote:
> 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
>
| |
|
| Sorry there is a typo in my example:
DECLARE @Criteria TABLE (CriteriaValue CHAR(1))
"Aiwa" wrote:
[color=darkred]
> 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
>
> "Greg" wrote:
>
|
|
|
|
|