sql case statement

 

WITH
dt (idx, FISCAL_YR_VAL, FISCAL_YY) as
(
select
ROW_NUMBER() over (order by years.yr) as idx, yr as FISCAL_YR_VAL , yr-2000 as FISCAL_YY
from (select top 5 ROW_NUMBER() over(order by a.name) + 2014 as yr from sys.all_objects a) years
where years.yr < 2017 +1

) ,

dx (idx, FISCAL_YR_VAL, FISCAL_YY) as
(
select
ROW_NUMBER() over (order by years.yr) as idx, yr as FISCAL_YR_VAL , yr-2000 as FISCAL_YY
from (select top 5 ROW_NUMBER() over(order by a.name) + 2014 as yr from sys.all_objects a) years
where years.yr < 2017 +1

)

Select
* ,
case
when idx > 1 then 3
else idx
end evnt_typ
from dt ;

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s