DBA > Job Interview Questions > Sybase Interview Questions and Answers

Convert months to financial months in Sybase

More DBA job interview questions and answers at http://dba.fyicenter.com/Interview-Questions/

(Continued from previous question...)

Convert months to financial months in Sybase

To convert months to financial year months (i.e. July = 1, Dec = 6, Jan = 7, June = 12 )

Method #1
select ... ((sign(sign((datepart(month,GetDate())-6) * -1)+1) *
(datepart(month, GetDate())+6))
+ (sign(sign(datepart(month, GetDate())-7)+1) *
(datepart(month, GetDate())-6)))
...
from ...


Method #2
select charindex(datename(month,getdate()),
" July August September October November December
January Febuary March April May June
" ) / 10

In the above example, the embedded blanks are significant.

(Continued on next question...)

Other Job Interview Questions