lamer lamer lamer lamer - 6 months ago 12
SQL Question

how to get previous year (month december) and month showing current month in sql

I have list of datetime value. How to select previous year just for december only.

For example:

Current month = May 2016
Previous year of december = Dec 2015
(it will display data from dec 2015 to may 2016)

if Current month = May 2017
Previous year of december = Dec 2016 and so on.
(it will display data from dec 2015 to may 2016)


Any idea ? Thank you very much

Answer
SELECT 
*
FROM
TableName
WHERE
TableName.Date BETWEEN CONVERT(DATE,CONVERT(VARCHAR,DATEPART(YYYY,GETDATE())-1)+'-12-'+'01') AND GETDATE()