I’m debugging a java application which heavily uses t-sql stored procedure. Sometimes I get the post’s title error. I think I’ve found the place where the error happens, but T-SQL isn’t among my skills. Can anybody confirm that I’m right and suggest a solution please?
SQL Server 2005 stack trace show the following messages :
set @prezzoUnitario2f = funcCtrlConvertToFloat] (@prezzoUnitario2)
IF @prezzoUnitario2f IS NULL OR cast(@prezzoUnitario2f as varchar) = '' OR @prezzoUnitario2f < 0
SET @defaultValue = NULL
IF ((select ISNUMERIC(@valueIn)) = 1)
Error: 8114, Severity: 16, State: 5
Error converting data type varchar to float.
This is where the stored procedure calls the funcCtrlConvertToFloat function :
set @prezzoUnitario2f = [C4].[dbo].[funcCtrlConvertToFloat] (@prezzoUnitario2) --CONVERT(float,replace(@prezzoUnitario2,',','.'))
This is the funcCtrlConvertToFloat function :
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[funcCtrlConvertToFloat]
(
@valueIn varchar(100)
)
RETURNS float
AS
BEGIN
DECLARE @defaultValue float
DECLARE @returnValue float
SET @defaultValue = NULL
--SET @valueIn = ISNULL(@valueIn, 0)
IF ((select ISNUMERIC(@valueIn)) = 1)
BEGIN
SET @returnValue = CONVERT(float,replace(@valueIn ,',','.'))
END
ELSE
BEGIN
SET @returnValue = @defaultValue
END
RETURN @returnValue
END
As I’ve told I’m not a T-SQL programmer, so any hint would be appreciated
I guess the following should solve your problem: