?
Solved

MSSQL query to return results based on a list of inputs

Posted on 2014-11-06
3
Medium Priority
?
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 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 66

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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 different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

765 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