Tinkinc
Tinkinc

Reputation: 454

Case WHEN Date to String

I have a view that is pulling from a table that will be constantly updated can I use a case when that automatically takes the date column and provides me the string ( 'YYYY-MM') for every month ( all 12 and mutiple years as the table it draws from grows.

Currently I have this for every month

CASE WHEN t1.DATE_OF_SERVICE_3013 BETWEEN TO_DATE('01/01/14','MM/DD/YY') AND TO_DATE('01/31/14','MM/DD/YY') THEN '2014-01' ..... End ) as Year_Month

I would like the YEAR_MONTH to be When DATE_OF_SERVICE_3013 is falls in month X then give me Year_MONTH as 'YYYY-MM' for year is the year represented in DATE_OF_SERVICE_3013

thanks kindly.

Upvotes: 0

Views: 37

Answers (1)

Clint Street
Clint Street

Reputation: 339

I think you could use Format such as this:

 CASE WHEN t1.DATE_OF_SERVICE_3013 BETWEEN TO_DATE('01/01/14','MM/DD/YY') AND TO_DATE('01/31/14','MM/DD/YY') THEN Format(t1.DATE_OF_SERVICE_3013,"yyyy-mm") ..... End ) as Year_Month   

Upvotes: 0

Related Questions