I'm working on a query that needs to be converted from Oracle to SQL for SSMS. I am stuck at this portion though:
WHERE
(irrelevant to question portion of query)
AND add_dt BETWEEN NEXT_DAY (TRUNC(SYSDATE) - 12, 'Monday')
AND NEXT_DAY (TRUNC(SYSDATE) - 6, 'Monday')
I understand what this does in Oracle, however, I am struggling with the conversion to T-SQL in SSMS.
I appreciate any help given!
I've tried to research converting NEXT_DAY
to GETDATE
and TRUNC
to DATETIME
but the SYSDATE
is what is getting me.
1条答案
按热度按时间9njqaruj1#
In Oracle, your query is identical to:
Which can be converted to SQL Server as:
Or, from SQL Server 22:
However, I'm not sure that you want to have the start and end dates of the range 6 days apart because you will get data from an 8-day period most days of the week but on Saturdays you only get a single day.
If you ware expecting to always get a range of 7 days then what you probably want is, in Oracle:
Or SQL Server:
Or, SQL Server 2022:
Oracle fiddle
SQL Server fiddle