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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:02:22+00:00 2026-06-12T16:02:22+00:00

Why, when opening a query like the following: WHERE (statement1) AND ((statement2) OR (statement3))

  • 0

Why, when opening a query like the following:

WHERE (statement1) AND ((statement2) OR (statement3))

does SSMS query designer refactor it into the following syntax:

WHERE (statement1) AND (statement2) OR
(statement1) AND (statement3)

I assume it has something to do with how SQL server parses the query, running ands before ors?

Is there a general rule of how to the best order of statements for ultimate optimisation?

Having run my own tests, the 2nd query knocks 0.5ms off the processing time. Its small, I know, but would increase with the complexity of the query (still makes almost no difference) and I have a general interest in how SQL server works.

  • 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-12T16:02:23+00:00Added an answer on June 12, 2026 at 4:02 pm

    It has nothing to do with the actual SQL execution. Unlike most languages you know, T-SQL does not have boolean operator short circuit1 and concepts like ‘running ands before ors’ make no sense, the order of evaluation is entirely driven by the query optimizer decisions and the may end up being completely different from what you write, or what you expect.

    The expression rewrite you see seems to be entirely an artifact of the SSMS query designed internal parser.

    1 Or better said the boolean short circuit cannot be determined imperatively by how you write the expression. Actual run time operator short circuit does happen, you just can’t know if and when it will happen.

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

Sidebar

Related Questions

I need to run a query that looks would look like INSERT INTO Appointments
I have an insert query like this: INSERT INTO CONSUMER (CONS_ID_NO, LOCATION_ID, AREA_CODE, CONS_NO,
Opening an XML file in Internet explorer gives a security warning. IE has a
Im opening a map like this: NSString *urlString = [NSString stringWithFormat:@http://maps.google.com/maps?q=%@,%@, destLat, destLong]; [[UIApplication
I want to store the opening and closing hours of locations into a DB
I want to export my big SSMS (SQL Server Management Studio) query result (2.5m
I have an INSERT statement that looks like this: INSERT INTO officer (officer_number, name,
I am attempting to export a query from MS Access into MS Excel in
I have the following code in jquery, what it does is when the user
Exporting select query data from mysql to csv & opening with excel, the leading

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.