If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Conversion of integer field to char

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-10-05, 02:07
madhuri_awal madhuri_awal is offline
Registered User
 
Join Date: Dec 2004
Location: India
Posts: 23
Conversion of integer field to char

Hi all..
I have a column STAT in table INFO which is currently of integer data type. But while displaying I want to display it as Char(4).In most of the records the field is of 4 digits but in some records it is of 3 digits where I need to display it as '0***' (Left padded by zeroes).
How can I do it???
I tried CAST function as:

SELECT CAST (STAT AS CHAR(4)) FROM INFO;

But for 3 digit value it is displaying it as 3 digit only inspite of using char(4) in the cast statement. I want to display it as char(4).
How can I do it??
I tried coalesce also....But

Thanks in advance...
Madhuri
Reply With Quote
  #2 (permalink)  
Old 03-10-05, 02:50
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
May be ..

select
when stat<1000 then '0'||cast(stat as char(4)) else
cast(stat as char(4))
end
from info
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On