Multiple Parameters in the IN Clause

  • With a Teradata database the following query will run.

     

    select * from Table1

    where (id1, id2) IN

    (select (id1,id2) from Table2)

     

    This query will not run in SQL Server 2000.  The closest I can get is this:

     

    select * from Table1

    where CAST(id1 as varchar) + '_' + CAST( id2 as varchar ) IN

    (select CAST(id1 as varchar) + '_' + CAST( id2 as varchar ) from Table2)

     

    Does anyone have a better way to write a query that will accept multiple parameters in the IN clause?

     

    Any help is greatly appreciated!

  • why do you have to use IN?

    SELECT *

    FROM TableName

    WHERE Id1 = @ID1 AND ID2 = @ID2


    * Noel

  • How about using an inner join?  That should be simpler and more efficient.

    SELECT t1.*

    FROM Table1 t1 JOIN Table2 t2 ON t1.Id1 = t2.Id1 AND t1.Id2 = t2.Id2



    --Jonathan

  • thanks!  I was trying to make it to difficult!

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

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