I've switched companies and in doing so, switched from SQL Server
to Sybase-ASE
. I can't tell if I'm just having a brain fart and am coding incorrectly or if there is a difference between running Datediff(...Dateadd(...),Getdate())
in SQL Server
and Sybase-ASE
. I'm getting a type clash (INT)
on the Datediff
side of the formula when running the code below. Running Dateadd
by itself works fine. Not sure if something needs to be tweaked or it just can't be done in Sybase-ASE
. Any help? I checked these other questions but no real help (Subtract one day from datetime GETDATE last month Get the records of last month in SQL server Datediff GETDATE Add)
SELECT TOP 5 *
FROM SalesData fm
WHERE fm.Date = DATEDIFF(MONTH, DATEADD(MONTH,-1,MAX(fm.Date)),GETDATE())
ALSO, side question: I can't remember what the specific formula is to get the whole of last month is in Datediff
if anyone happens to know. I can figure it out I just figured it's best to kill two birds with one stone. It's apparently somewhat difficult to get a Dates
table implemented into production...
Nevermind, I got it thanks to this post(Get the records of last month in SQL server)
where DATEPART(MONTH,fm.Date) = DATEPART(MONTH, DATEADD(MONTH,-1,GETDATE()))
AND DATEPART(YEAR,fm.Date) = DATEPART(YEAR, DATEADD(YEAR,0,GETDATE()))