Literal value with "IN" clause

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Smith

    Literal value with "IN" clause

    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,


  • Erland Sommarskog

    #2
    Re: Literal value with "IN&quo t; clause

    John Smith (genericemailac count@genericdo main.genericTLD ) writes:[color=blue]
    > 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.[/color]

    That should be OK. A bit unusual maybe, but certainly valid.


    --
    Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

    Books Online for SQL Server 2005 at

    Books Online for SQL Server 2000 at

    Comment

    • --CELKO--

      #3
      Re: Literal value with "IN&quo t; clause

      >> 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.

      Comment

      Working...