case within select day, month functions



IBM's flagship relational database management system

case within select day, month functions

Postby k singh » Mon Dec 15, 2014 11:18 pm

hi

I am using day , month functions to get day and month from a timestamp column in select query.
i.e. select day(bb), month(bb) from aaa; (bb - columns name, aaa - table)
I am gettings correct results. if day is less than 10 is appears as a single digit. I want it to appear as double digits.
for ex. if day is 1 , I need "01" instead of "1".

I tried using case statement.
select month(bb), case when day(bb) < 10 then 0||day(bb) else day(bb) end as day from aaa;
but still I am not getting "01". day greater or equal than 10 are fine. its day from 0-9 have issues.

note : 0||day(bb) works fine if I use select month(bb),0||day(bb) from aaa; it concats 0 before every day.

any help on this one will be appreciated. or is there any other way to do it .

thanks and regards
k singh
 
Posts: 22
Joined: Fri Nov 21, 2014 8:38 pm
Has thanked: 9 times
Been thanked: 0 time

Re: case within select day, month functions

Postby k singh » Tue Dec 16, 2014 1:03 am

I was able to find the solution using VARCHAR_FORMAT(bb,'yyyymmdd')

thanks a lot for your help
k singh
 
Posts: 22
Joined: Fri Nov 21, 2014 8:38 pm
Has thanked: 9 times
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post