How do you create a SQL query in Excel 2007 with a dynamic date range?
- by Jordan
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.