IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2 - prefix values to result set column values


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
itjagadesh

New User


Joined: 05 Dec 2006
Posts: 89
Location: chennai

PostPosted: Fri Jul 31, 2009 10:37 pm
Reply with quote

Hi,

I need to retrieve a integer column as char(2) and I'm using this
char(char(Integer_column),2) syntax, now the results are retrieved as below
1
2
3
4
5
10
11
12
20
Now, I need to prefix single digit results with '0' so result should be like
01
02
03
04
05.

Could anyone suggest a query to achieve the expected results?

Thanks in advance,
Jagadesh.
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Mon Aug 03, 2009 9:31 am
Reply with quote

Try to use Length and concat function along with case.

Code:

CASE WHEN LENGTH(yourcolumn) =1
THEN  CONCAT(0,yourcolumn)
ELSE
     yourcolumn
END

Back to top
View user's profile Send private message
itjagadesh

New User


Joined: 05 Dec 2006
Posts: 89
Location: chennai

PostPosted: Mon Aug 03, 2009 1:57 pm
Reply with quote

It's working now.

Thank you Bharath!
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Mon Aug 03, 2009 2:05 pm
Reply with quote

You're Welcome. icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts How to load to DB2 with column level ... DB2 6
Search our Forums:

Back to Top