Updating All Rows

  • 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

  • you can use CASE with conditions.

  • UPDATE [TABLENAME]

    SET

    FULLNAME = FIRSTNAME + ' ' + LASTNAME

    Prasad Bhogadi
    www.inforaise.com

  • 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.

  • 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

  • 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