Retrieve rows for the last 3 months

Retrieving rows for the last 3 months:
This query is for retrieving the last 3 months data from sql table:
SELECT DISTINCT DATEPART(mm,DateColumnName) FROM Table
WHERE DateColumnName>= DATEADD(month,-2,GETDATE());/*Last 3 months*/
This query is for retrieving the last 3 months data from sql table:
SELECT DISTINCT DATEPART(mm,DateColumnName) FROM Table
WHERE DATEDIFF(Month,workdate,GETDATE()) > 3/*First 3 months*/

Discover more from QubitSage Chronicles

Subscribe to get the latest posts sent to your email.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.