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 Programming
 quick script to update rows with new data

Author  Topic 

tech
Starting Member

32 Posts

Posted - 2012-05-24 : 22:58:19
So I have an existing table of "user" data.
now a new field has been added: username.
username is now compulsary but you cannot just add the column and make it "NOT NULL".

so how can I (after alter table) update each row with a value for this new field by obtaining the value from the field "firstname" and 2 characters from the field "surname" and then finally from this concatination, update that row for the new field "username"?

i.e:

Firstname: steve
Lastname: tibbs

becomes:

username: steveti

thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-05-25 : 01:40:58
[code]
update yourtable
set username = firstname + isnull(left(lastname, 2), '')
[/code]


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

Go to Top of Page
   

- Advertisement -