March 20, 2006 at 1:29 am
My INT variable has got values ranging from the length of 4 to 5. on the conversion i need to pad the string with "00" to the left and if the length is 4 and pad it with "0" to the left if the length is 5.
my variable is
compound
2234
9100
9023
54101
60001
2034
how do i convert this into a string variable compoundid with the above condition?
March 20, 2006 at 2:04 am
Something like this?
create table #x ( digit int not null )
insert #x
select 2234 union all
select 9100 union all
select 9023 union all
select 54101 union all
select 60001 union all
select 2034
go
select digit, right('00' + cast(digit as varchar(6)),6)
from #x
go
digit
----------- ------
2234 002234
9100 009100
9023 009023
54101 054101
60001 060001
2034 002034
(6 row(s) affected)
/Kenneth
March 20, 2006 at 2:07 am
March 20, 2006 at 2:22 am
Thanks Kenneth, it has worked. i am greatful to ur advice.Great day.
March 20, 2006 at 4:15 am
use this simple Query :
select replace(str('2345',5),' ',0)
NOTE :
In place of '2345' you can use your Column. but it should be convert into a varchar type.
Regards ,
Amit Gupta
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply