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
 Database Design and Application Architecture
 Need to Update field by adding number to values

Author  Topic 

MikeTex
Starting Member

3 Posts

Posted - 2011-01-12 : 18:00:40
I have a table of employees numbered 001 to 999, I need that in this table are the records altered so that they begin to be numbered from 0001 to 9999, changing existing ones from 001 to 0001 ...
Can anyone help me please.
Thanks.

MikeTtx

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-01-12 : 18:19:44
why not just use an int data type instead of monkeying around with characters types to hold numbers?
Go to Top of Page

MikeTex
Starting Member

3 Posts

Posted - 2011-01-12 : 19:12:12
how do I do that?
Thanks

MikeTtx
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-12 : 19:35:34
+1 to russell's post.

If you continue down this bad design, what happens when you have more than 9,999 employees? Will you then need to add an additional zero? This is a bad design. You need to switch to an integer instead of character data.

Trim off the leading zeroes and then convert it to int.

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

Subscribe to my blog
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-01-12 : 19:37:01
Change the column to int datatype

Alter Table [TableName] alter column [columnname] int not null




Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

MikeTex
Starting Member

3 Posts

Posted - 2011-01-13 : 02:56:57
No problem about more than 9,999 employees, the Database owner only want's it this way, because this Database will not be used for mutch more time. That way they want to only add a leading zero.
Thanks alot.

MikeTtx
Go to Top of Page
   

- Advertisement -