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

  • Home
  • SEARCH
  • 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 8081467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:44:15+00:00 2026-06-05T16:44:15+00:00

Why, when you run this, do you get 2.00 as the answer? declare @temp

  • 0

Why, when you run this, do you get 2.00 as the answer?

declare @temp int  = 2
select CASE WHEN @temp = 1 THEN cast(@temp as decimal(5, 2))
         WHEN @temp = 2 THEN  @temp
         ELSE NULL
    END

But if you run this, you get 2 as the answer when selecting just @temp2

declare @temp2 int = 2
select CAST(@temp2 as decimal(5,2))
select @temp2

Bridge is correct:

Returns the highest precedence type from the set of types in result_expressions and the optional else_result_expression. (Source)

Data Type Precedence

  • 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-05T16:44:16+00:00Added an answer on June 5, 2026 at 4:44 pm

    I believe the return value has to be the same datatype for each possible output from the case statement. It considers the possible outputs, and tries to cast them all to the same type.

    The first possible return value there is of type decimal(5, 2), and second of type int. It chooses the datatype with the highest presidence that can hold both values, and automatically casts all the outputs to this for you.

    Your second script is behaving as expected. You actually get two values output:

    • 2.00 – which is the result of the cast in the second line
    • 2 – which is the value of @temp2 – which is an int, you assigned it on the first line
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error FB is not defined when i try to run this
If I run this code on IE8 or lower, I get this error: Object
When I run this C code: // Get rid of the CRT and stuff;
I run this piece of code on Visual C++ 2010 char c[10]; cin.get(&c[0],5); cin.get(&c[2],4);
I was wondering how to get this to run. In my application I have
When I try to run this code, I get incorrect maximums and minimums. Could
If I run this demo on the HTC Hero (CyanogenMod 6.1.0) I get a
When I run this code to call the Google API, all I get is
I get this error when I run the code below. I have normally used
When I compile and run this with Visual C++ 2010: #include <iostream> int main()

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.