Scott Palmer
asked on
Syntax for putting a varible in a date in SQL
I need to know the syntax for putting a date in SQL in Access with a variable.
This is what i want:
dim vYear as Date
vYear = Year(Now)
WHERE FinalDate = 1/1/vYear
vYear is the of course the variable.
Thanks,
Scott
This is what i want:
dim vYear as Date
vYear = Year(Now)
WHERE FinalDate = 1/1/vYear
vYear is the of course the variable.
Thanks,
Scott
ASKER
I am trying to find the data parameters for each year for year to date reporting so the whole WHERE column is this dummy code.
WHERE FinalDate Between 1/1/vYear and 12/31/vYear
What i currently have is this:
WHERE FinalDate Between 1/1/2014 and 12/31/2014
And i was updatting so I would not have to change my code every January with the new year
Also the variable vYear could be the current year or it could be the previous month's year when it is january.
WHERE FinalDate Between 1/1/vYear and 12/31/vYear
What i currently have is this:
WHERE FinalDate Between 1/1/2014 and 12/31/2014
And i was updatting so I would not have to change my code every January with the new year
Also the variable vYear could be the current year or it could be the previous month's year when it is january.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Gustav is correct. That is why I was hoping to just add variable vYear after 1/110 or 12/31/ that way I would not have to add the longer SQL statement all throughout out my, I could do it once when the form is opened. So there is no way to do this?
Scott
Scott
ASKER
Thanks, I can use the code once when the form opens and store that in a variable for the from and to date.
Scott
Scott
You are welcome!
/gustav
/gustav
WHERE FinalDate = dateserial(year(now()),1,1