i am trying to convert below oracle query to SQL server query.
Select * from table A
WHERE TRUNC(a.Generate_DATE,'MM') = (SELECT (NVL (TRUNC (TO_DATE ('$$date','MM/DD/YYYY HH24:MI:SS')),TRUNC(ADD_MONTHS(SYSDATE, -1),'MM'))) FROM DUAL)
where $$date is parameter value and will be passed from outside the query.
The issue is with dateformat.I am unable to convert this exact format in sql server.
To get the first day of the month use
dateaddandday, egFor
NVLuse the standard coalesce function.For
TRUNCusecast(getdate() as date)For
ADD_MONTHS(SYSDATE, -1)usedateadd(month,-1,getdate())or go get the SQL Server Migration Assistant for Oracle, which will translate Oracle SQL and PL/SQL to TSQL for you. It also installs a bunch of compatibility functions so with SSMA this is translated to: