I have a query to display the year value from a table and default the current year.
select distinct year(startdate) as syear, year(startdate) as eyear, 1 as sOrder from [TTS].[dbo].[Class] where year(startdate) <> year(getdate())
union all
select year(getdate()) as syear, year(getdate()) as eyear, 0 as sOrder
order by sOrder asc, syear desc
Here default year is 2015 (with Sorder 0) . Now I Need to display the Default Year based on month value. For e.g if year is 2015 and months are in jan,feb,mar,april then default year is 2015. else default year is 2016. i have tried the below query
select distinct year(startdate) as syear, year(startdate) as eyear, 1 as sOrder from [TTS].[dbo].[Class] where
year(startdate) <> year(getdate())
union all
select year(getdate())+1 as syear, year(getdate())+1 as eyear, 0 as sOrder where month(getdate()) not in(1,2,3,4)
union all
select year(getdate()) as syear, year(getdate()) as eyear, 0 as sOrder where month(getdate())in(1,2,3,4)
order by sOrder asc, syear desc
But year values are getting duplicated. can any help me in this?