Solved

MSSQL query to return results based on a list of inputs

Posted on 2014-11-06
3
145 Views
Last Modified: 2016-02-11
I have the need to run a query based on the data that is saved in an excel spreadsheet.  The spreadsheet has two columns and about 100 rows.  The two values in each row will be plugged into the sql query.  The query should loop through the list.  Honestly, I can put the list in whatever format is best for this process.

My guess is that SSIS may server me best, but I have never do the looping needed to make the query run each row.  Below is the very simple query with Column1 and Column2 as the variables.  The Column1 data is formatted as 0000 and the Column2 data is formatted as 00000.

Please be detailed in your response because my query knowledge is somewhat limited.

select * from MHGROUP.DOCMASTER
where C1ALIAS = 'Column1' and C2ALIAS = 'Column2'
0
Comment
Question by:TPBPIT
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40426669
>Please be detailed in your response because my query knowledge is somewhat limited.
The extremely low-tech solution would be...

1.

>The Column1 data is formatted as 0000 and the Column2 data is formatted as 00000.
Eyeball the data types of DOCMASTER.C1ALIAS and .C2ALIAS, and write them down.

2.

In SSMS, click on your database, then do a right-click > Tasks > Import Data... and follow the prompts to connect to your Excel doc and create a new table, let's call it Table1, with columns Column1 and Column2, with the data types noted in Step 1.   Using this wizard avoids the step of having to create an SSIS package.

3.

Execute the below query in SSMS:
SELECT dm.* 
FROM MHGROUP.DOCMASTER dm
   JOIN Table1 t1 ON dm.C1ALIAS = t1.Column1 AND dm.C2ALIAS = t1.Column2

Open in new window

0
 

Author Closing Comment

by:TPBPIT
ID: 40427220
I had to convert the file to a tab delimited text file, but it worked like a champ.  Thanks for the help!
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40427235
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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…
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

830 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