UPDATE STATEMENT

  • Newb question, but hey...

    I am trying to update a column (CustPhone)

    format = XXXXXXXXXX

    I need to set the area code = 664 in the rows with a 614 area code.

    One of the numbers is 614614XXXX.

    My answer returns 664664XXXX

    I want 664614XXXX.

    My brain hurts.

    HELP

  • STUFF(CustPhone,1,3,'664') WHERE left(Custphone,3) = 614

    "Keep Trying"

  • LIKE I said, I'm new, so STUFF ...

    Is that a function?

    I would really appreciate a conceptual explanation.

    Wandrag-- can I UPDATE and return a table with only the affected rows, all in the same query?

    How do I give that row a column heading or alias?

    Much appreciated.

  • Weird name for a function.

    All I want to do is return the affected rows after they are modified. No biggie. But if there is a shortcut...

  • Wandrag (10/22/2008)


    No - you can't update and return results in the same query.

    What do you want returned? The records before update, or after the update?

    In SQL 2005 you actually can return the updated records in one query using the OUTPUT clause. Again see in BOL for more info or here:

    [font="Verdana"]Markus Bohse[/font]

  • +1 for OUTPUT clause

    That is something new I learned recently too, which is quite cool

    It's almost like TRIGGER's DELETED and INSERTED "hidden" tables

    STUFF

    http://msdn.microsoft.com/en-us/library/ms188043.aspx

    SQLServerNewbieMCITP: Database Administrator SQL Server 2005

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply