code in sql to get last 6 months data code example Example: sql where last 12 months select Dateadd(Month, -12, GETDATE())