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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Updating existing data with new Value

Author  Topic 

isihalin
Starting Member

6 Posts

Posted - 2009-09-23 : 06:42:02
HI All,

I have been managing SQL server 2000 Database for my company.I have a Field Name called e_code (employee code which is unique)in a Master table and has been mapped as Foreign Key to more than 5 tables.
Now that , our Employee code has been changed in the recent past, I need to update the employee code with one letter in-front of the existing e_code , now if this is for one or two i can manually update it. But it needs to be done for all

Is there a way i can change the ecode for all with one update statement.

Scenario:
Exisiting Data : e_code='1011280'
To be Changed : e_code='e1011280'
Any help ?



Thanks In Advance.
isihalin

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-23 : 06:51:56
[code]
update t
set e_code = 'e' + e_code
from yourtable t
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

isihalin
Starting Member

6 Posts

Posted - 2009-09-25 : 05:13:22
Hi

Thanks. It works.



update t
set e_code = 'e' + e_code
from yourtable t
[/code]


KH
[spoiler]Time is always against us[/spoiler]


[/quote]

Thanks In Advance.
isihalin
Go to Top of Page

nalnait
Starting Member

14 Posts

Posted - 2009-09-25 : 08:25:13
1?UPDATE TABLE SET col='e'+col

2?alter foreign key as cascade update
Go to Top of Page
   

- Advertisement -