Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Multiple columns IN support Expand / Collapse
Author
Message
Posted Wednesday, September 26, 2012 3:38 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 26, 2012 3:07 AM
Points: 5, Visits: 20
Hi All,
Currently I am working on oracle to MS SQL server migration project.

SQL select query in Oracle:

Select ID, NAME in EMP_TBL where (ID, NAME) in (('1','foo1'), ('2','foo2')).

What is the alternate solution in MS SQL Server 2008?




Post #1364527
Posted Wednesday, September 26, 2012 3:41 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 2:37 AM
Points: 5,075, Visits: 4,834
One way would be the need to compare each column individually like below.

SELECT 
ID,
Name
FROM
EMP_TBL
WHERE
ID IN (1,2)
AND
Name IN ('foo1','foo2')





Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1364531
Posted Wednesday, September 26, 2012 3:51 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 26, 2012 3:07 AM
Points: 5, Visits: 20
Thanks very much for your reply.
Post #1364537
Posted Wednesday, September 26, 2012 3:54 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Thursday, April 10, 2014 10:18 AM
Points: 1,769, Visits: 2,800
Does the Oracle query check both values in a row? Which would be this:

SELECT 
ID,
Name
FROM
EMP_TBL
WHERE
(ID = 1 AND Name = 'foo1')
OR
(ID = 2 AND Name = 'foo2')

Post #1364538
Posted Wednesday, September 26, 2012 3:57 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, April 08, 2014 6:13 AM
Points: 1,694, Visits: 19,550

SELECT ID, NAME
FROM EMP_TBL
INTERSECT
(SELECT '1','foo1'
UNION ALL
SELECT '2','foo2')



____________________________________________________

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537

Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #1364541
Posted Wednesday, September 26, 2012 5:13 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 26, 2012 3:07 AM
Points: 5, Visits: 20
Any performance issues if there are more values in IN clause?
Post #1364574
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse