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 3317136
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:33:07+00:00 2026-05-17T22:33:07+00:00

Hi all SQL Server Blackbelt masters out there. I have a simple question that

  • 0

Hi all SQL Server Blackbelt masters out there.

I have a simple question that I need to solve. I am trying to do some quirky update on a table. Specific structure of the table is not important and my problem can essentially be reduced to the following one:

update SalesTotal
set @total = total = @total + sales,
@flag = flag = case when @flag = 1 then 0 
                    when @total > x then 1
                    else 0 end

The question is CAN I TRUST that @total variable will have a new value ie. will execute before the second set part, or will it contain an “old” value (from previous assignment) or it is undefined. I am pursuing this problem for some time now, and can’t find a solution and it is really important for my update (I want to update a table in one go). One of the values I want to update depends on the value of the other (in the same row) so the only way for it to work in a single update is if it works.

Hope You can help me

  • 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-05-17T22:33:07+00:00Added an answer on May 17, 2026 at 10:33 pm

    No, you cannot make any assumption of imperative order of execution. There is absolutely no guarantee about the order of the updates tacking place in the table, there is absolutely no guarantee that the @variable is updated once for each table SET, and the update may well run with a spool step for Halloween protection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create several applications that all share a Microsoft SQL Server database.
In SQL Server 2000, you have the All Tasks... - Export Data option. Where
In SQL Server 2005, are there any disadvantages to making all character fields nvarchar(MAX)
I need to enumerate all the user defined types created in a SQL Server
We have a SQL Server 2005 database, and currently all our users are connecting
I am using SQL Server 2005, I want to find out what all the
We have a Single Statement FUNCTION in SQL Server 2005 which uses CONTAINSTABLE(). All
If all my sql server database access is done thru stored procedures, and I
In SQL Server how do you query a database to bring back all the
My log file in SQL Server used up all the space on my disk.

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.