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)
 Pad with Zero

Author  Topic 

iloveorangesoda
Starting Member

30 Posts

Posted - 2008-04-16 : 06:08:16
I am doing a select statement from a table and want to pad a field with a zero if the value is between 1 and 9. The field is a char(2)

Anyone give me example of how to do this.

cheers


harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-16 : 06:16:24
[code]select right('00' + rtrim(col),2) as col from table[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

iloveorangesoda
Starting Member

30 Posts

Posted - 2008-04-16 : 07:46:28
great thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-16 : 08:34:04
quote:
Originally posted by harsh_athalye

select right('00' + rtrim(col),2) as col from table


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"


Or

select right('0' + rtrim(col),2) as col from table

Provided the column is not empty

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -