SQL Server | Other
Additional SQL Server features and topics not covered by specific categories
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi.
I need to get the max date of the last month in the table. Query can do this?
create table testtbl(EID int,INDATE datetime);
insert into testtbl values(10001,'07/31/2023');
insert into testtbl values(10011,'08/23/2023');
insert into testtbl values(10021,'07/26/2023');
insert into testtbl values(10031,'08/09/2023');
insert into testtbl values(10041,'08/13/2023');
insert into testtbl values(10051,'09/20/2023');
Additional SQL Server features and topics not covered by specific categories
Answer accepted by question author
Hi @Vks
If I understand correctly, you need to query ‘08/23/2023'.
You can try this query.
select max(INDATE) from testtbl
where INDATE > eomonth(dateadd(month,-2,getdate()))
and INDATE <= eomonth(dateadd(month,-1,getdate()));
Best regards,
Percy Tang