Results 1 to 7 of 7

Thread: Data Formating

  1. #1
    Join Date
    Jul 2004
    Posts
    268

    Unanswered: Data Formating

    Hi,

    I have a data in the column that is displayed like 3 Y 2 M 1 W 0 D. I need to replace Y with years, M with month, W with weeks, and D with days. Also, I need to check if there is 0 Y, or 0 M, or 0 W, or 0 D, don't display it at all. I am trying to use decode but it isn't working. Please help. Thanks.

  2. #2
    Join Date
    Mar 2002
    Location
    Reading, UK
    Posts
    1,137
    probably best to use nested replaces

    i.e.

    select replace(replace(col,'0 Y',' '),'Y','Year') from table

    and include replaces for M,W,D aswell.

    Alan
    Last edited by AlanP; 10-22-04 at 13:04.

  3. #3
    Join Date
    Jul 2004
    Posts
    268

    Data Formating

    Could you give me a complete query with replaces for M,W,D? I am trying to add that but I am getting overwhelmed. Thanks a lot.

  4. #4
    Join Date
    Jul 2004
    Posts
    268

    Data Formating

    I just discovered another problem. I have records that only have values like 60 D, and by using the query that you provided 0 D is being removed, and that makes sense. How can I modified the query to keep 60 D, and remove the values that have 0 D? Thanks a lot.

  5. #5
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    Would you mind posting some sample row data and the output you want ?

  6. #6
    Join Date
    Jul 2004
    Posts
    268

    Data Formating

    Sure.

    Here is the data I have:

    3 Y 5 M 4 W 0 D
    60 D
    0 Y 0 M 20 W 8 D
    2 Y
    6 M
    1 Y 6 M

    Output I want:

    3 years 5 months 4 weeks
    60 days
    20 weeks 8 days
    2 years
    6 months
    1 years 6 months

  7. #7
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    On the surface this question appears to me to be a classic homework problem.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

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