Query Help

  • I have a reference table like this,

     

    Col A

    Col B

    Col C

    Col D

    1

    2

    3

    4

    5

    6

    7

    8

    I have another table on which I have to check for a particular column for all the cell values existing in the reference table.

    Somthing like this.

    Select * from order where ord_id in (1,2,3,4,5,6,7,8)

    The above query should be dynamic.

    Any thoughts.

    Cheers,

    Ganesh

     

     

  • This should work, though it's a bit ugly

    SELECT * FROM order WHERE ord_id IN

    (

    SELECT Col_A FROM Ref UNION

    SELECT Col_B FROM Ref UNION

    SELECT Col_C FROM Ref UNION

    SELECT Col_D FROM Ref

    )

    HTH

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks a lot. It worked fine.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply