Solved

SQL Query - Multiple where clause

Posted on 2014-04-14
3
552 Views
Last Modified: 2014-04-14
Hi,

I have an excel sheet contains about 300 rows of data.  I needs to run a SQL select query that extracts these 300 records from a table containsing 50k records. Obviously returning a single record would be easy to do, but I don’t know how to do it for so many?

Any pointers? – using SQL 2008.

TIA.
0
Comment
Question by:andyw27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Wasim Akram Shaik earned 500 total points
ID: 39998482
you can use in clause and place the whole set of records there

for ex:, you would be doing like this for a single record

select * from table where column_name=<column_value_from_excel>

you could use the in clause and place all column values separated by a comma like this

select * from table where column_name in(<column_value_from_excel,column_value_from_excel,column_value_from_excel>,column_value_from_excel..)

eg:

select * from emp where deptno in(10,20,30)

where emp is the table and deptno is the column of that table

alternatively you use use formula generator in excel and prepare a formula using concat operator for each cell and dynamically place the column value, so that you could get 300 different queries, but i suggest first one using an in clause is better option
0
 

Author Comment

by:andyw27
ID: 39998576
cool, looks good.  Is there any way to expand this so that I can do it against two columns:

something like this:

select * from emp where deptno in(10 + col2 value ,20 + col2 value,30 + col2 value)
0
 

Author Comment

by:andyw27
ID: 39998661
Now sorted, just concatenated the two strings.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question