Solved

SQL Query - Multiple where clause

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

821 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