Search code examples
sqldb2export-to-excel

db2 sql query in excel


I have a number of very simple queries that I run for others on my team and am placing them in Excel so that the end user can just execute the query themselves by opening the spreadsheet.

I'm currently using an ODBC driver to connect to the DB2 server.

All queries work fine but one is giving me a headache in getting it to work correct in Excel.

One of the queries has a where statement that equals a different value depending on the situtation.

ex.

SELECT * 
FROM TABLE1 T1 
WHERE T1.T1_ID = 859745

What I would like is to set it up so that the query runs like the following. Is it possible to do this through a variable somehow?

SELECT * 
FROM TABLE1 T1 
WHERE T1.T1_ID = "USER ENTERED VALUE FROM COLUMN A ROW 1 IN THE EXCEL SHEET"

Solution

  • I'm assuming you're using Microsoft Query. First add a parameter to the query. Then you can customize your parameter to choose an excel cell an the input for the paramter

    enter image description here