sql server - How to find last 10 years using sql query -
i working on sql query have find last 10 years. suppose 2015 then query should return 2015,2014,2013... , on. have used following query-
select top 10 datepart(year,getdate()) order datepart(year,getdate()) desc
but above query returning single query current year. please me here.
try this:
with yearlist ( select (datepart(year,getdate())-10) year union select yl.year + 1 year yearlist yl yl.year + 1 <= year(getdate()) ) select year yearlist order year desc;
Comments
Post a Comment