SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

Vack
Constraint Violating Yak Guru

USA
495 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

visakh16
Very Important crosS Applying yaK Herder

India
52309 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
http://visakhm.blogspot.com/


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

madhivanan
Premature Yak Congratulator

India
22744 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

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
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000