• Jeff Moden (7/20/2013)


    Adi Cohn-120898 (7/9/2013)


    Jeff – Sorry for disappearing, but for some reason I missed your response. What I wanted to do was very simple. I was working on improving performance on a stored procedure. One of the changes that I've made was to make fewer data access statements. In the procedure there was a code that looked like that:

    Select @OldValue = Col1 from MyTable where PK=X

    Update MyTable SET Col1 = NewValue where PK=X

    I wanted to access the table only once instead of twice.

    Adi

    The problem with that is that it will only handle one row at a time. I agree that's the way you designed it with the PK=X but what is the larger picture? Is this something that you need to do with a batch of rows?

    It will always be for 1 record. If this would have been with more then few records, I would have used output clause with temporary table.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/