Pad length

  • Comments posted to this topic are about the item Pad length

  • I think I may have a use for this, thanks.

  • In my case, I needed to add the 'N' parameter for @UseFixedLength in the SELECT statement to avoid an error regarding invalid number of arguments. Also the result displayed for the 2nd Pad at Front example was not correct. The syntax I'm using for the SELECTS is as follows:

    Pad at Front:

    -------------

    SELECT dbo.[KDT_FN_PADLEN]('11','0',7,'Y','N')

    will result in

    000000011

    SELECT dbo.[KDT_FN_PADLEN]('11','0',7,'Y','Y')

    will result in

    0000011

    Pad at Back:

    -------------

    SELECT dbo.[KDT_FN_PADLEN]('11','0',7,'N','N')

    will result in

    110000000

    SELECT dbo.[KDT_FN_PADLEN]('11','0',7,'N','Y')

    will result in

    1100000

  • Couldn't this have been simplified with the REPLICATE function?

    SELECT REPLICATE(@CharsTobePaddedWith, @PadLenght) + @PaddedChar

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:
    http://www.sqlservercentral.com/articles/61537/

  • Michael makes a great point!

    You can use the REPLICATE function to accomplish this much more simply, and

    if needed you could use the DATELENGTH() string function to set the length

  • Awesome Thanks for the feedback:-)

    I will definitively use the REPLICATE function, and rewrite the code.

    There is always more than one way to skin a cat; but who skins cat's these days.

Viewing 6 posts - 1 through 5 (of 5 total)

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