Solved

MSSQL query to return results based on a list of inputs

Posted on 2014-11-06
3
131 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
Comment Utility
>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
Comment Utility
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
Comment Utility
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

My client has a dictionary table. They're defining a list of standard naming convention. Now, they are requiring my team to provide us a mechanism how to match new incoming data with existing data in their system.
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 information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

763 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

10 Experts available now in Live!

Get 1:1 Help Now