SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 "IN" in Select
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

asutoshv
Starting Member

India
2 Posts

Posted - 08/02/2005 :  04:15:11  Show Profile  Reply with Quote
I've a problem in a query, it is performing in Oracle but not working in Sql:

select * from tabA a where (a.sr_no, a.nm) in ((1,'a'),(2,'b'),(3,'c')) ;
tabA is :
sr_no number(3),
nm varchar(10)

If you have any solution or alternate, plz inform asap.
Thank You.

madhivanan
Premature Yak Congratulator

India
22713 Posts

Posted - 08/02/2005 :  04:17:29  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Try this

select * from tabA a where a.sr_no in (1,2,3)
and a.nm in ('a','b','c')


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

asutoshv
Starting Member

India
2 Posts

Posted - 08/02/2005 :  04:21:40  Show Profile  Reply with Quote
Sorry, but it wont work like that.
my question is i've to select records like :
select * from tabA where (a.sr_no = 1 and a.nm = 'a') or (a.sr_no = 2 and a.nm = 'b') or(a.sr_no = 3 and a.nm = 'c')

so instead of writing these many 'or' and 'and's can it work like :
select * from tabA a where (a.sr_no, a.nm) in ((1,'a'),(2,'b'),(3,'c')) ;
Go to Top of Page

Kristen
Test

United Kingdom
22403 Posts

Posted - 08/02/2005 :  04:39:01  Show Profile  Reply with Quote
That style of IN is not supported in SQL and I can't think of an easy workaround if you are using Dynamic SQL.

You could put the values into a temporary table (perhaps passing them as a delimited string, and "splitting" that into a temporary table?) along the lines of

SELECT [num]=1,[letter]='a'
INTO #MyTempTable
UNION ALL SELECT 2,'b'
UNION ALL SELECT 3,'c'

select * 
from tabA a
     JOIN #MyTempTable T
         ON T.num = a.sr_no
        AND T.letter = a.nm

Kristen

Edited by - Kristen on 08/02/2005 04:39:38
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22713 Posts

Posted - 08/02/2005 :  04:53:28  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
If your data in the table are as follows

sr_no nm
1 'a'
2 'b'
3 'c'

No need of checking the nm value
Can you post some sample data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000