I have the following command:
SELECT CAST(450/4 AS DECIMAL(15,2))
Return : 112 where the right one would be 112.5
Why this?
NOTE: My SCRIPT is in a procedure, but roughly my problem is in this select
I have the following command:
SELECT CAST(450/4 AS DECIMAL(15,2))
Return : 112 where the right one would be 112.5
Why this?
NOTE: My SCRIPT is in a procedure, but roughly my problem is in this select
According to the documentation:
/ (Division) (Transact-SQL)
link
The division return type will be the highest precedence type ( When writing a numeric constant with decimal point, SQL Server will understand that number is of type Constants (Transact-SQL) or that: It should also work. decimal
:
SELECT CAST(450.0/4.0 AS DECIMAL(15,2))
decimal
:
Since
link decimal
has precedence higher than int
, I believe that only one of the constants could be of type decimal
so that the return is of type decimal
also, so this way:
450/4.0
450.0/4