Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Posts
    8

    Post Unanswered: Filling empty characters

    Hi,

    I am importing barcodes however they are all different lengths and I need to bring them all up to 14 characters by adding zero's to the beginning of them (up to when the field is full).

    The only way I can think is doing a count on the char length and then adding zero's in a loop but I think there must be an easier way? Any help appreciated.

    Thanks
    Tim

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    What about this?

    declare @line varchar(50),@len int
    set @line='12345'
    set @len=10
    select isnull(replicate('0',@len-len(@line)),'')+@line

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    ..or the more low-tech:

    set @line = right(14, '00000000000000' + @line)

    blindman

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    how low can you go?

    Hey, I have to lookup just to see the top of the gutter....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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