0

Good Day

i have been hit by this error this night.

I have a UDF defined like this

    CREATE FUNCTION [dbo].[funcFormatPercentages_Extended_numeric]
    (

     -- Add the parameters for the function here

     @parPercentageToBeFormatted nvarchar(20)

    ) 
    RETURNS nvarchar(20)

    AS

    BEGIN 
         RETURN CAST(CAST(convert(float,@parPercentageToBeFormatted)* 100 AS decimal(4, 1)) AS nvarchar(5)) + N'%'  
    END 

so i will call the UDF with the value like this

select [dbo].[funcFormatPercentages_Extended_numeric]('-43.4703076923077') 

OR

 select [dbo].[funcFormatPercentages_Extended_numeric]('36.403813624481') 

i get an Error

Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type nvarchar.

I tried to change the datatypes and Precision around , but still the error.

Thanks

Edited by vuyiswamb

2
Contributors
1
Reply
9
Views
4 Years
Discussion Span
Last Post by pritaeas
0

Perhaps the casting to a decimal fails because you are not rounding first. Does this fail too?

select [dbo].[funcFormatPercentages_Extended_numeric]('36.4')
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.