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
 General SQL Server Forums
 New to SQL Server Programming
 Update field with leading zeros

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2010-11-10 : 10:17:27
I have a field that is char 15

I want to update the field so that it has leading zeros in it.

Table name: altsls
Field Name: cus_cd

data in field is 1. I want it to be 000000000000001

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-11-10 : 10:19:24
[code]
UPDATE altsls
SET cus_cd = RIGHT('000000000000000' + cus_cd ,15)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-11 : 04:44:31
If it is only for selection

select replace(STR(cus_cd ,15),' ','0') from altsls

updation

update altsls
SET cus_cd =replace(STR(cus_cd ,15),' ','0')

Madhivanan

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

- Advertisement -