Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2004
    Location
    India
    Posts
    23

    Unanswered: 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

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •