Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2016

    Unanswered: convert char value to integer

    Hi All,

    I have svc_yr_mth values stored as yyyymm format , i want to extract only year and convert to integer. values are as 201601, 201602,201604,201501,201502
    i am doing this way cast(substr(c.svc_yr_mth,1,4) as integer) as svc_yr. is there a better way to do this. and also i have to do some calculations to find the right age.
    cast(b.mbr_age - (b.svc_yr - cast(substr(d.svc_yr_mth,1,4) as integer)) as integer). please correct me as


  2. #2
    Join Date
    Apr 2008
    Iasi, Romania
    Provided Answers: 3
    I usually CAST the entire string to integer and then divide the result by 100: the integer result is the year, while the modulo is the month.
    You have just one CAST and then operations with numbers.
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

Posting Permissions

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