April 8, 2008 at 8:54 am
Ok, It is early here, and I cannot think of how to accomplish this task.
I would like to update a single column in one table. The updated data comes from other columns in the same table. This is only an experiment, this is not the actual data in the table. I would never store duplicate data. Having said that, here is my table
FirstName, LastName, FullName
I would like to concatenate FirstName and LastName and Update the FullName column with such.
How can I do this for the entire table without passing in the RowID of each row. I want to write a single query that will update the entire table, by firing off the query only once.
Thanks
Andrew SQLDBA
April 8, 2008 at 8:56 am
you can use CASE with conditions.
April 8, 2008 at 8:59 am
UPDATE [TABLENAME]
SET
FULLNAME = FIRSTNAME + ' ' + LASTNAME
Prasad Bhogadi
www.inforaise.com
April 8, 2008 at 9:04 am
A CASE statement will allow you to do more complicated stuff. Your exact request can be done without...
update Employees set FullName = FirstName + ' ' + LastName
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
April 8, 2008 at 9:15 am
Thanks Everyone
I think this was so simple that I could not think clearly about it.
I had the concatenation part correct, I was thinking that the update would be more complicated. I ran a simple update statement, and it did exactly what it was supposed too.
I think that I may need a day off.
Thanks again
Andrew SQLDBA
April 8, 2008 at 9:23 am
For what it's worth - why not make that a computed column? That way you won't have to worry about fullname getting out of synch with last and and first names?
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply