Monday, March 26, 2012

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?

ThanksTry:

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|||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.....

No comments:

Post a Comment