Unanswered derived column query

  • Friday, August 31, 2012 4:36 PM
     
     

    how to extract month and year part together from date in derived column.

    Ex-date-2010-12-21

    Desired result-201012 (i.e-concatenation of year and month)

    Reply as soon as possible

    Thanks in advance

    Sunny Prakash

All Replies

  • Friday, August 31, 2012 4:56 PM
     
     
    Use (DT_WSTR,4)YEAR(<DateTime Column>) + (DT_WSTR,2)MONTH((<DateTime Column>) )

    http://btsbee.wordpress.com/

  • Friday, August 31, 2012 5:01 PM
     
     

    Better still use this

    (DT_WSTR,4)YEAR(<DateTime Column>) + REPLICATE("0",2 - LEN((DT_WSTR,2)MONTH(<DateTime Column>))) + (DT_WSTR,2)MONTH((<DateTime Column>))

    as the above will pad single digit months with leading zeroes.


    http://btsbee.wordpress.com/

  • Friday, August 31, 2012 7:59 PM
    Moderator
     
      Has Code

    how to extract month and year part together from date in derived column.

    Ex-date-2010-12-21

    Desired result-201012 (i.e-concatenation of year and month)

    Reply as soon as possible

    Thanks in advance

    Sunny Prakash

    Or use

    SUBSTRING(REPLACE((DT_WSTR, 20)DateColumn,"-",""),1,6)

    which is shorter


    Arthur My Blog