Results 1 to 3 of 3

Thread: Arithmetic overflow error converting expression to data type nvarchar.

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Arithmetic overflow error converting expression to data type nvarchar.

    Good Day

    i have been hit by this error this night.

    I have a UDF defined like this


    Code:
    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

    Code:
     
    select [dbo].[funcFormatPercentages_Extended_numeric]('-43.4703076923077')
    OR
    Code:
    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

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Arithmetic overflow error converting expression to data type nvarchar.

    I don't know what the effect on the math is but nvarchar(5) is too small. Making it eight or greater will make that work.

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Re: Arithmetic overflow error converting expression to data type nvarchar.

    That error indicates that the float might not have enough to store the value. It is not a problem with varchar. Use double instead of float (in you cast statement).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width