1

I'd like to put a SQL query in an Excel 2010 spreadsheet where one of the columns in the SELECT will be a parameter.

I've played around with it for a bit with different table aliases and changing the command text from within the connection properties box with no success. It just gives me various errors with each attempt. I tried googling but found nothing on the subject. I suspect that it is simply impossible to do this using a standard database query as MS query is quite limiting. Can someone verify that it is indeed impossible to have a SQL query in Excel with a column name in the SELECT as a parameter? If it is not impossible could you share how to get it to work?

It'd be something like...

SELECT tble.Date, tble.Hour, tble.[parameter]
FROM my_table tble

I'd want some parameterized wheres once I got the above to work.

Dean MacGregor
  • 11,847
  • 9
  • 34
  • 72
  • `1.`Can you show us your select query? `2.`Are you looking for a parameterized query..? `3.` What does this mean ***impossible to have a SQL query in Excel with a column name in the SELECT as a parameter***? Is the column name coming from `database` or `Excel Sheet`? – bonCodigo Feb 01 '13 at 14:13
  • I added more specifics to my question. The column name would come from Excel Sheet. I meant in the SELECT before the FROM clause. – Dean MacGregor Feb 01 '13 at 14:19

1 Answers1

0

Could this be the query string that you are looking for? Assuming you are getting data from cells where cell range act as the table in this case:-

SELECT ID, NAME, ADDRESS
FROM   [Sheet1$A1:C20]
WHERE  ID = [Sheet1$E2]

References:

Community
  • 1
  • 1
bonCodigo
  • 14,268
  • 1
  • 48
  • 91