Converting decimal field (Hours Worked) to varchar(6) and displaying in a specific format (2080.00 --> 208000)

  • I need help with converting a decimal field (Hours Worked) to a varchar field.

    Required format:

    2080.00 hrs. should be displayed as 208000

    780.50 hrs. should be displayed as 078050

    Other than a case statement that determines the lenght, I'm not sure how to make sure the leading zeroes are included.

    Any help would be appreciated.

    Thanks,

    Jeff

  • select

    HoursWorked =

    right('0000000000'+convert(varchar(10),convert(int,a.HoursWorked*100)),6)

    from

    ( -- Test Data

    select HoursWorked = 2080.00 union all

    select HoursWorked = 780.50

    ) a

    Results:

    HoursWorked

    -----------

    208000

    078050

  • I'll give this a try.

    Thanks for your quick response.

  • That worked great. I didn't think of it that way.

    Merry Christmas.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply