Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7877817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:29:05+00:00 2026-06-03T03:29:05+00:00

My question has to do with the order of updates in a single update

  • 0

My question has to do with the order of updates in a single update statement. I have observed that when I set variables using a SELECT statement, that the variables are set in order. For example:

SELECT
    @Test1 = 2,
    @Test2 = @Test1 + 1

At this point @Test1 will be 2 and @Test2 will be 3 because the set operations are done in order. But what happens with UPDATE?

UPDATE TestTable SET
    Test1 = 2,
    Test2 = Test1 + 1

Will Test2 use the initial value of Test1 in its calculation or will it use the value we just set? Does it make any difference if it is an UPDATE statement inside of a MERGE?

MERGE INTO TestTable AS T
    USING (
        SELECT
                Test1,
                Test2
            FROM SomeOtherTable
        ) AS S
        ON S.Test1 = T.Test1
    WHEN MATCHED THEN
        UPDATE SET
            T.Test1 = 2,
            T.Test2 = T.Test1 + 1
    ;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:29:07+00:00Added an answer on June 3, 2026 at 3:29 am

    The names on the right hand side of the assignment refer to the old values of the columns, regardless of the order they are in.

    This (for example) allows you to swap two values without using a temporary variable.

    UPDATE foo
    SET a = b,
        b = a
    

    http://sqlfiddle.com/#!3/f6984/1


    The SQL-92 specification (Section 13.10, General Rules, Item 6 on page 395) states:

    • The <value expression>s are effectively evaluated for each row of T before updating any row of T.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that has some minor visual preferences that are set in
My question has two parts: Is it possible that, if a segfault occurs after
I have a JSON object with an array of updates, where each update consists
I have a Ruby on Rails app that has a scheduled job I execute
In my Rails 3 app, I have a list of questions. Each question has
I have a WCF client, that asks for order confirmation and WCF service with
I have an Update method in my repository which I'm using to update articles
This is a question that I have been pondering for a long time ,
I'm building an ordering system. And here I have an Order class, which has
This question has developed off an answer here . My question therefore is what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.