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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:14:34+00:00 2026-06-18T03:14:34+00:00

I need some information about processing order of the Searched CASE WHEN statement in

  • 0

I need some information about processing order of the Searched CASE WHEN statement in SQL.

For example:

(CASE
     WHEN Cells.Type <> 'UOM' THEN 0
     WHEN Template_Colors.Uom_Case = 'ONE' THEN 1
     WHEN Template_Colors.Uom_Case = 'MUL' THEN 2
 END) AS CELL_WHAT_UOM

I need the result to be always 0, unless Cells.Type <> 'UOM'.

I know that SQL parsers usually proceed from the bottom to the top, but in Oracle the query seems to work correctly, so I suppose that WHEN clauses are processed in the order they are.

It is 100% guaranteed that the 0 case is processed before the others?

Or I have compulsorily to write:

(CASE
     WHEN Cells.Type <> 'UOM' THEN 0
     WHEN Cells.Type = 'UOM' AND Template_Colors.Uom_Case = 'ONE' THEN 1
     WHEN Cells.Type = 'UOM' AND Template_Colors.Uom_Case = 'MUL' THEN 2
 END) AS CELL_WHAT_UOM

…?

I need this information about Oracle 10g + SQL server 2008 r2 + Postgre.

  • 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-18T03:14:35+00:00Added an answer on June 18, 2026 at 3:14 am

    If Cells.Type is not equal to UOM, you’re guaranteed that the result will be 0.

    What you are not guaranteed (certainly in SQL Server) is that any expressions in the other branches will not be computed.

    So, if you did the following:

    CASE WHEN a = 0 THEN 0 ELSE 10/a END
    

    You might get a division by zero error.


    And, even in your example:

    WHEN Cells.Type = 'UOM' AND Template_Colors.Uom_Case = 'ONE' THEN ...
    

    There is no guarantee on the order in which predicates are evaluated, so Template_Colors.Uom_Case may still be accessed. Not sure what your concern is around whether this column is accessed or not, so no further advice to offer at the present moment.


    SQL Server documentation:

    • Evaluates, in the order specified, Boolean_expression for each WHEN clause.

    • Returns result_expression of the first Boolean_expression that evaluates to TRUE.

    • If no Boolean_expression evaluates to TRUE, the Database Engine returns the else_result_expression if an ELSE clause is specified, or a NULL value if no ELSE clause is specified.

    Oracle:

    In a searched CASE expression, Oracle searches from left to right until it finds an occurrence of condition that is true, and then returns return_expr. If no condition is found to be true, and an ELSE clause exists, Oracle returns else_expr. Otherwise, Oracle returns null.

    PostGre:

    If the result is true then the value of the CASE expression is the result that follows the condition. If the result is false any subsequent WHEN clauses are searched in the same manner.

    Ansi 92 (draft):

    If the <search condition> of some <searched when clause> in
    a <case specification> is true, then the value of the <case
    specification>
    is the value of the <result> of the first
    (leftmost) <searched when clause> whose <search condition> is
    true, cast as the data type of the <case specification>.

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

Sidebar

Related Questions

I am writing one tool and I need to gather some information about running
I need some information about using cocos2d in iPad. Can we use 2048x2048 sprite
I'm writting diploma work about JavaFX 2.0, and I need some information about further
I need some expert information about ActiveX and some valuable experience reports from those
I need to access some information about the element that was bound to a
I need some information about code-signing certificates. I have no idea how they work,
I need some information about localization. I am using .net 2.0 with C# 2.0
I need to have some information about the scoping in JavaScript. I know that
I need to be able to store some information about the user and I
Im just starting with localization today and need some information. I have a project

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.