Wednesday, 27 March 2013

How to retrieve last 6 months data in sql server

How to retrieve last n months data in sql server ?


Query :


  SELECT *
  FROM [db1].[dbo].[Data]
  where  entry_date >= dateadd(mm,datediff(mm,0,getdate())-6,0)


Parameter :  Pink color marked data object worked as n number of months .

Output :

Display last 6 months data from current date.



No comments:

Post a Comment