Change date in a SQL query to reference a cell in Excel

Posted by Adil on Super User See other posts from Super User or by Adil
Published on 2012-12-09T16:49:59Z Indexed on 2012/12/09 17:06 UTC
Read the original article Hit count: 262

Filed under:
|
|

I have the following code that returns the needed data into excel and manually changing the date will change the returned data; however, I'd like to reference a cell with a formula that will make the query a bit more user friendly.

I've tried using my limited knowledge of referencing a cell but none have worked. This information is in cell A1 and the query is placed in cell A2 with the following equation: =wwQuery("STKAP03", $A$1)

SET QUOTED_IDENTIFIER OFF
SELECT * FROM OPENQUERY(INSQL, "SELECT DateTime, [40_MOTORS.MI436423.CIN], [40_MOTORS.MI436425.CIN]
FROM WideHistory
WHERE [40_MOTORS.MI436423.CIN] IS NOT NULL 
AND wwRetrievalMode = 'Delta'
AND wwVersion = 'Latest'
AND DateTime >='20120409 07:00:00' These two dates/times I'd like to reference cells on a different sheet
AND DateTime <= '20120416 07:00:00'")

© Super User or respective owner

Related posts about sql

Related posts about date