How do you create a SQL query in Excel 2007 with a dynamic date range?

Posted by Jordan on Super User See other posts from Super User or by Jordan
Published on 2012-06-06T21:54:27Z Indexed on 2012/06/06 22:42 UTC
Read the original article Hit count: 315

Filed under:
|
|
|

I am trying to create a reporting spreadsheet that can print reports for a given time period. The query below works, but when I try to use a "?" parameter in place of the date, I get an error after selecting a cell containing my date. If I use single quotes ('?') I get a conversion from string to date/time failure, if I don't (?) I get a syntax error near @p1. Eventually I will need either a start and end date or a formula adding a month or shift to the starting date/time to filter the data down to important information. The query was built in Microsoft Query.

SELECT FloatTable.DateAndTime, TagTable.TagName FROM master.dbo.FloatTable FloatTable, master.dbo.TagTable TagTable WHERE FloatTable.TagIndex = TagTable.TagIndex AND ((FloatTable.DateAndTime>={ts '2012-06-01 00:00:00'}))

Any assistance would be much appreciated. Thanks in advance.

© Super User or respective owner

Related posts about microsoft-excel

Related posts about sql