Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Tinyint Arithmetic overflow

$
0
0

Newbie question. I've searched the forum but can't see an answer for this, apologies if exists...

I have 2 fields "Class" which are numbers from 1 to 9, and "Class_LT" which are numbers from 1 to 9 or null, both are defined as tinyint.

I am trying to create a new field which is one minus the other ie.

cast(case when DATA.[Class_LT)]>0 then DATA.[Class]-DATA.[Class_LT] else null end as varchar(1)) as Class_Chg

ideally I want this new field "Class_Chg" to be a smallint, but tried that and the varchar above. Always get a tinyint overflow error, but I am not trying to define as a tinyint (as the result maybe anything from -8 to +8 or null). 

Any ideas what I am doing wrong?

Many thanks.


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>