Concatenate 2 fields with first field having fixed length

  • I did this code in ORACLE with lpad and rpad but I cannot figure out the sql server code to do this

    ORACLE CODE: (RPAD(SHIFTLABEL),6)||LPAD('0',3)

    I have two fields that I want to query and when they appear on the report, I want the first field to be a fixed length

    This is what I am using but I have tried several different variations. The original size of SHIFTLABEL is 30

    (left((SHIFTLABEL),6)) + (' 0')

    This is what I am getting with the first field being a variable length. I want the first field to be a fixed length of 6

    D 0

    DD 0

    DDD 0

    and I want to see the 0s lined up on the right

    ORACLE CODE WORKED perfect

    :crazy:

  • Try this:

    SELECT LEFT(SHIFTLABEL+ replicate('0',6),6)

  • Thank you Grasshopper. I just figured out a different way after finding an old post on this site 🙂 but I appreciated your reply

    (CAST(SHIFTLABEL AS CHAR(6))) + ' 0'

    This one works like a charm!

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

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