mercredi 9 août 2017

If/Then/Else in Formatting a Date

I am trying to get the fiscal period and year out of an invoice date. Using the month() function together with the Case I am able to get the period. since Period 1 is in November I need to do a +1 1 the year when this is true

Using the IF function together with the date functions are now working for me.

My query is

Select a.OrderAccount 
,a.InvoiceAccount
,a.InvoiceDate
,year(a.InvoiceDate) as Year
,month(a.InvoiceDate) as Month,
Case month(a.InvoiceDate) 
WHEN '11' THEN '1' -- increase year by +1 
WHEN '12' THEN '2'-- increase year by +1 
WHEN '1' THEN '3' 
WHEN '2' THEN '4'
WHEN '3' THEN '5'

Any advice would be appreciated. Thanks

Aucun commentaire:

Enregistrer un commentaire