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!

Padding Existing Records

Status
Not open for further replies.

jkruer01

Programmer
Feb 4, 2003
3
0
0
US
Hello,

I have about 2,000 records that I need to pad with leading zeros. The field is a character field of length 6. Right now, some of the records have 6 digits in them(which is the way I want them to be) but some only have 3 digits in them. I need to pad all of the records with only 3 digits with 3 leading 0's.

Does anyone know of an easy way to do this?

Example some records have 123 in it and I want it to be 000123.

Any suggestions would be appreciated.

Thanks!
 
Hi JK

Try this

SELECT (WHEN LENGTH(RTRIM(xxxxx)) =3 THEN
CHAR(000) CONCAT CHAR(xxxxx)
ELSE xxxxx
END ) AS yyyy

Hari
TCS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top