Solved

TSQL CASE Statement Error SQLServer 7(Msg 8115, "Arithmetic overflow error converting numeric to data type numeric.")

Posted on 2003-11-28
2
1,300 Views
Last Modified: 2011-09-20
SQLServer 7
Watch out for this one…

Statement Below Works
Select
CASE d.AmPmAll
WHEN 1 THEN 0.5
WHEN 2 THEN 0.5
WHEN 3 THEN 1.0 --CORRECT
END TimeOfDayNum
from  Dayoff d


Statement Below Fails
Select
CASE d.AmPmAll
WHEN 1 THEN 0.5
WHEN 2 THEN 0.5
WHEN 3 THEN 1 --INCORRECT
END TimeOfDayNum
from  Dayoff d

Server: Msg 8115, Level 16, State 8, Line 1
Arithmetic overflow error converting numeric to data type numeric.

The ".0" makes a big difference eh!

FYI - d.AmPmAll is a tinyint field; Posted to save someone else time.
0
Comment
Question by:GJPerkins
  • 2
2 Comments
 
LVL 6

Accepted Solution

by:
lausz earned 20 total points
ID: 9837244
The problem is that you have to manage the same data type for all the case statement ..is for this taht you need to use 1.0-

0
 
LVL 6

Expert Comment

by:lausz
ID: 9837263
I tested your sample in sql 2000 and it works in the two ways. I don't know in 7.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question