HKFuey
asked on
SQL Syntax
I'm trying to understand someone else's syntax: -
These are the parameters: -
DECLARE @TodayStart AS DATETIME, @TodayEnd AS DATETIME
SET @TodayStart = DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)
SET @TodayEnd = DATEADD(dd, 1, @TodayStart)
This is the 'where' part of the query: -
WHERE [ReceiptDate] >= '''+@TodayStart+'''
AND [ReceiptDate] < '''+@TodayEnd+'''
Can anyone tell me what date range will be returned by this query?
These are the parameters: -
DECLARE @TodayStart AS DATETIME, @TodayEnd AS DATETIME
SET @TodayStart = DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)
SET @TodayEnd = DATEADD(dd, 1, @TodayStart)
This is the 'where' part of the query: -
WHERE [ReceiptDate] >= '''+@TodayStart+'''
AND [ReceiptDate] < '''+@TodayEnd+'''
Can anyone tell me what date range will be returned by this query?
ASKER
So, even though it is convoluted, the results will be transactions from 'Today'?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's very clear, thanks very much!
You can also replace SET @TodayStart = DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)
with SET @TodayStart = convert(varchar, getdate(), 111), which is just trimming the time part from datetime value.
with SET @TodayStart = convert(varchar, getdate(), 111), which is just trimming the time part from datetime value.
SET @TodayStart = DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)
SET @TodayStart = getdate()
daterange is from today until tomorrow