I read all the posts with similar questions but couldn't find a working solution.
What I try to do is take value from excel cell and put it in a SQL query (again in excel) so when the value is changed, the SQL query is also changed accordingly.
For example I have two sheets in a workbook and in Sheet 1 I have two dates in cells a2 and b2. I want to pass them in a SQL query so the data extracted is constrained between these two dates.
The query I tried in different syntax variants is:
SELECT
[INSTANCEDATE]
FROM
[hrsb].[dbo].[cVBAY]
WHERE
INSTANCEDATE >= [sheet1$a2]
AND INSTANCEDATE <= [sheet1$b2]
This does not work. I usually get an error that column b name is invalid. Seems that it doesn't make difference between excel values and DB parameters.
Of course, if instead of reference to excel cell values, I put just date range it works.
Could you please advise how this can be done?