View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.links,microsoft.public.excel.querydao,microsoft.public.excel.worksheet.functions,microsoft.public.sqlserver.connect
DM Unseen
 
Posts: n/a
Default Variable SQL Statements pulling from a cell in Excel

Use http://vangelder.orcon.net.nz/ QueryEditor to get around this
limitation.
BTW a table cannot be a variabl/parametere in an SQL query so you'll
need to update the SQL statement manually for each TABLE.
Using VBA would be the best. Here is some speudo code you could use
after you created the Query manually first

DIm qtb as QueryTable
DIm strTable as String
Const Query = "Select * FROM %TABLE% where year=?"

Set qtb = Activesheet.QueryTables(1)
qtb.CommandText = Query
strTable = Inputbox("Enter a table Name")
qtb.CommandText = replace(Query,"%TABLE%",strTable)
qtb.refresh

DM Unseen