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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update field with leading zeros
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Aged Yak Warrior

530 Posts

Posted - 11/10/2010 :  10:17:27  Show Profile  Reply with Quote
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

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 11/10/2010 :  10:19:24  Show Profile  Reply with Quote

UPDATE altsls
SET cus_cd = RIGHT('000000000000000' + cus_cd ,15)

SQL Server MVP

Edited by - visakh16 on 11/10/2010 10:20:09
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 11/11/2010 :  04:44:31  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
If it is only for selection

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


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


Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000