Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 repeating characters

Author  Topic 

mikejohnson
Posting Yak Master

153 Posts

Posted - 2004-12-13 : 11:10:14
in tsql is there anyway to repeat a certain character a certain number of times? for example, the space(4) puts 4 spaces into whatever you want. Except, i need something other than a space......

mikejohnson
Posting Yak Master

153 Posts

Posted - 2004-12-13 : 11:11:06
or is there anyway to take a number like 1 or 10 and place leading 0's in front of it depending on it's length?
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-12-13 : 11:18:20
SELECT STUFF('1', 1, 0, Replicate('0',5))

Corey
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-12-13 : 11:20:56
see replicate in bol.

to right justify in 20 chars with leading zero
select right(replicate('0',20) + convert(varchar(20),@i), 20)

Similar ting works for left justification.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -