By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,265 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,265 IT Pros & Developers. It's quick & easy.

Literal value with "IN" clause

P: n/a
Howdy,

Is it okay to use a literal value with the IN clause. E.g.

SELECT somefield, anotherfield
.....
WHERE ...etc.
AND 1234 IN (SELECT userid FROM tblUsers)

I was told it wasn't valid, but I'm pretty sure it worked for me. Just
seeking clarification.

cheers,
Apr 12 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
John Smith (ge*****************@genericdomain.genericTLD) writes:
Is it okay to use a literal value with the IN clause. E.g.

SELECT somefield, anotherfield
....
WHERE ...etc.
AND 1234 IN (SELECT userid FROM tblUsers)

I was told it wasn't valid, but I'm pretty sure it worked for me. Just
seeking clarification.


That should be OK. A bit unusual maybe, but certainly valid.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 12 '06 #2

P: n/a
>> I was told it wasn't valid, but I'm pretty sure it worked for me. <<

It is valid, Standad SQL and can be a useful trick to avoid OR-ed
predicates. The IN() list just has to be expressions that will cast
to the proper data type.

Apr 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.