April 6, 2005 at 3:01 pm
A question on WHERE clause syntax
IN DB2, i could use the following syntax :
SELECT a,b,c FROM TableXYZ
WHERE (a,b,c) in (1,2,3)
But , when i use the same in T-SQL , i get an error saying invalid syntax:
Line 1: Incorrect syntax near ','.
Is this type of syntax not allowed in T-SQL?
April 6, 2005 at 3:15 pm
This is invalid syntax. Correct syntax is
WHERE <ColumnName> IN (values)
If you need to test all 3 coumns a, b anc c against the values, you need 3 separate IN() clauses
WHERE a IN (1,2,3) OR b IN (1,2,3) OR ... etc
April 6, 2005 at 3:17 pm
SELECT a,b,c FROM TableXYZ
WHERE a in (1,2,3)
and b in (1,2,3)
and c in (1,2,3)
depending on what you really need and want you could also do another query like:
SELECT a,b,c FROM TableXYZ
WHERE (a in (1,2,3)
or b in (1,2,3)
or c in (1,2,3))
mom
April 6, 2005 at 3:22 pm
Thanks to all for your inputs.
I knew that i could do it by using a separate IN clause for each column, but i felt that the syntax WHERE (a,b,c) IN (1,2,3) was more elegant. Looks like T-SQL doesn't allow the above type of syntax.
Thanx
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply