Home All Groups Group Topic Archive Search About

AND clause BUT across rows

Author
25 Oct 2006 7:59 PM
grd
Lets say I have the following table.

---------------------------------------------
KEY             |     Value
---------------------------------------------
1000                   1
1000                   3
1000                   5
1000                   19
1000                   22

2000                   1
2000                   5
2000                   6
2000                   9

3000                   2
3000                   3
3000                   7


I want to return Distinct 'KEY'  where there is a value of 1 AND 3

In the above example only KEY 1000 would be returned

However I would like to pass in my values to match VALUE to a store
proc and I would like to quantity of numbers to be variable

e.g.

EXEC GetDistinctBasicKey '1,3'
or perhaps
EXEC GetDistinctBasicKey '1,3,5'
or perhaps
EXEC GetDistinctBasicKey '7'

The list may grow to up to 25 values
eg. EXEC GetDistinctBasicKey '1,2,3,4....,24,25'

I may be restricted to SQL Server 2k but if there are helpful options
in 2005 let me know anyhow.

Dickster

AddThis Social Bookmark Button