Why am I getting an error when passing an integer to a decimal in my stored procedure?

Why am I getting an error when calling my stored procedure?

this fails:

exec dbo.foo 100

but it works:

exec dbo.foo 99

definition:

CREATE PROCEDURE dbo.foo
(
   @latitude DECIMAL (16,14)
)
AS
BEGIN
    PRINT 'OK'
END

error message:

Msg 8114, Level 16, State 1, Procedure foo, Line 0
Error converting data type int to decimal.
+3
source share
2 answers

decimal (16.14) means "16 digits, 14 after the decimal point . " This means 2 to the decimal point. "100" is out of range because it is 3 numbers ...

Quick example

DECLARE @fail decimal(16, 14), @pass decimal(17, 14)

BEGIN TRY
    SET @pass = 100
END TRY
BEGIN CATCH
   PRINT 'Will not see this'
END CATCH

BEGIN TRY
    SET @fail = 100
END TRY
BEGIN CATCH
   PRINT 'Will see this'
END CATCH
+12
source

, , , . DECIMAL , ; 16. - , . , 100 DECIMAL(16,14), 99.99999999999999.

+3

Source: https://habr.com/ru/post/1792350/


All Articles