Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format A string

Status
Not open for further replies.

besto1a

Programmer
Aug 20, 2006
41
0
0
GB
I have a some strings some 9 charactors long and some 10 long.

I need all my strings to be 12 didgets long, so I need to add "00" to the front of my 10 didget strings and "000" to my 9 didget string

Is there any kind of format funtion to do this

Thanks

 
DECLARE @tbl_numbers TABLE
(
mynumbers varchar(12)
)

insert into @tbl_numbers values ('12345678')
insert into @tbl_numbers values ('12345678')
insert into @tbl_numbers values ('123456789')
insert into @tbl_numbers values ('123456789')


declare @reqsize int
set @reqsize = 12

select replicate('0',@reqsize-len(mynumbers)) + mynumbers from @tbl_numbers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top