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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Leading Zeroes

Status
Not open for further replies.

bjr149

Programmer
Jul 18, 2005
26
US
I have this command : convert(varchar(3),@Counter)


As i do this i want to put leading zeroes on the string.

So if counter is 5, i want it to print out 005. Thanks for the help
 
I see that you are converting to varchar, which is good. Now, simply put 3 zeros in front of the number, and then take the last 3 characters. Like this...

Code:
Declare @Counter Int
Set @Counter = 5

Select Right('000' + Convert(VarChar(3), @Counter), 3)

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top