Solved

SQL Query - Multiple where clause

Posted on 2014-04-14
3
535 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 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now