Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2002
    Posts
    46

    Unanswered: Feeding "0"'s in a string

    hi,
    I have this command in Vb that feeds "0" in a string, and I need it to work in a SP.

    ProductNum = format(ProductNum, String(nBarCodelength, "0"))

    if ProductNum = "12345" and nBarCodelength = 10
    the result of the above will be "0000012345" (the numbers were fed with "0").

    placing that command in a SP raises me an error.
    What replaces 'format' and 'String' commands in TSQL?

    Thanks

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    Try:

    declare @string varchar(20)
    select @string = '12345'
    select stuff(@string,1,0,replicate('0',10 - len(@string)))

    or

    declare @string varchar(20)
    select @string = '12345'
    select replicate('0',10 - len(@string)) + @string

  3. #3
    Join Date
    Aug 2002
    Posts
    46
    Originally posted by rnealejr
    Try:

    declare @string varchar(20)
    select @string = '12345'
    select stuff(@string,1,0,replicate('0',10 - len(@string)))

    or

    declare @string varchar(20)
    select @string = '12345'
    select replicate('0',10 - len(@string)) + @string
    I will try it.
    Many thanks mate......

Posting Permissions

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