Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Query - Multiple where clause

Posted on 2014-04-14
3
Medium Priority
?
569 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
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Wasim Akram Shaik earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

886 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