vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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, |
| |||
| John Smith (genericemailaccount@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, esquel@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 |
| ||||
| >> 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. |