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 Administration
 alter table

Author  Topic 

Leonel
Starting Member

10 Posts

Posted - 2012-10-23 : 18:48:51
i have this customer table(customer_id,customer_number,company_name, Address, etc)
i was asked to change the customer_number field and add a zero in front of all the records, so we can then import another customer list .
i dont know if this is posssible in sql , is there a way to run a querry so i can just put a zero in the begining like so(12, would be 012)
the customer table look like this:

customer_number name
4041 Optima Bank and Trust
83 Water Street Bookstore
80 North Main Music
4042 City of Dover
4043 Manchester Community Health
4044 6 Junkins court LLC

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-10-23 : 18:52:02
What data type is customer_number?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Leonel
Starting Member

10 Posts

Posted - 2012-10-23 : 18:55:46
varchar(30) not null
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-23 : 18:57:25
yep do like

UPDATE table
SET customer_number = STUFF(customer_number,1,0,'0')

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

Go to Top of Page

Leonel
Starting Member

10 Posts

Posted - 2012-10-23 : 21:00:27
Got it thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-23 : 21:30:51
welcome

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

Go to Top of Page

Kannan475
Starting Member

3 Posts

Posted - 2012-10-25 : 11:43:46
quote:
Originally posted by visakh16

yep do like

UPDATE table
SET customer_number = STUFF(customer_number,1,0,'0')

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





Great, Can we just do this
Update TableName set Customer_Number = '0'+Customer_Number
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-25 : 12:27:00
quote:
Originally posted by Kannan475

quote:
Originally posted by visakh16

yep do like

UPDATE table
SET customer_number = STUFF(customer_number,1,0,'0')

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





Great, Can we just do this
Update TableName set Customer_Number = '0'+Customer_Number



Sure why not
so far as Customer_Number is character datatype it will work. otherwise might require a cast

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

Go to Top of Page
   

- Advertisement -