Solved

SQL Query - Multiple where clause

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help how to find where my error is in UFD 6 29
SQL Server - Set Field Values ito Zero Based on Related Table 4 25
Update a text value in another table 10 40
SQL view 2 27
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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.
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.

773 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