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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:36:30+00:00 2026-06-13T04:36:30+00:00

Found an interesting problem on SQL Server yesterday, try this: DECLARE @a REAL =

  • 0

Found an interesting problem on SQL Server yesterday, try this:

DECLARE @a REAL = 0.0000
DECLARE @c DECIMAL (18,10) = 20754/3.45 -- this is 6015.6521730000
DECLARE @b DECIMAL (18,10) = 
CASE 
    WHEN 1 > 2 
        THEN @a / 100
    WHEN 1 = 2
        THEN 56
    ELSE @c
END

SELECT @b

It seems to be a problem with precision, and how the case statement is compiled. It can be easily remedied by casting the REAL @a to a decimal in the case statement, but as it’s @c we’re returning and the other cases should never be hit, it’s a strange problem to come across.
Anyone know enough about SQL compilation to explain this?

  • 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-13T04:36:31+00:00Added an answer on June 13, 2026 at 4:36 am

    It’s down to Data Type Precedence, as detailed in the documentation

    [CASE] Returns the highest precedence type from the set of types in result_expressions and the optional else_result_expression.

    http://msdn.microsoft.com/en-us/library/ms181765(v=sql.100).aspx

    You can break it entirely by adding the line

    WHEN 1 = 3 then getdate()
    

    There’s a more detailed explanation here

    I imagine that the compiler assumes that all cases may be possible (your example is of course deliberately perverse 🙂 )

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

Sidebar

Related Questions

I found interesting problem with Win7/X64 machine. For this time I haven't got problem
I found a pretty interesting problem installing ruby gems bluehat@Matapan:~/code/Amacron$ rails server --debugger =>
I found this interesting behavior. Why could this happen I am using the cmdlet
I found this interesting site, that helps me understand derivatives, http://www.numberempire.com/derivatives.php , It seems
In Matters Computational I found this interesting linear search implementation (it's actually my Java
I found an interesting algorithmic problem. We are given a binary tree which has
found a interesting problem during testing our web application. I have application on localhost
I just found an interesting problem between translating some data: VB.NET: CByte(4) << 8
Here's an interesting problem: I have some jQuery that looks like this: $(document).ready(function() {
I've found an interesting problem in my WPF app related to a MultiDataTrigger not

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.