Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting error 'Error converting data type nvarchar to float.' while inserting a record in the table using stored procedure.

My stored Procedure is

SQL
USE [ezNew_db]
GO
/****** Object:  StoredProcedure [vipl-user].[SP_Copy_Bill_InsertData]    Script Date: 01/06/2015 09:31:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [vipl-user].[SP_Copy_Bill_InsertData](@tablename nvarchar(50)  ,@INV_NO nvarchar(50),@AC_NO nvarchar(50),@AC_NAME nvarchar(255),@INV_DATE nvarchar(50),@AD1 nvarchar(255),@AD2 nvarchar(255),@AD3 nvarchar(255),@AD4 nvarchar(255),@AD5 nvarchar(255),@AD6 nvarchar(255),@TERMS nvarchar(30),@EXCHANGE_RATE float,@CREATED_BY nvarchar(10),@DATE_CREATED nvarchar(50),@ZERO_RATED_INV bit,@TAX_INCLUDE bit,@Deleted bit,@SEAL_NO nvarchar(50),@JOB_NO nvarchar(255),@Inv_Amt nvarchar(50),@GST nvarchar(50),@Inv_Net nvarchar(50),@Status nvarchar(50)) as
begin
Declare @sql nvarchar(max)
set @sql='insert into '+@tablename+'([INV_NO],[AC_NO],[AC_NAME],[INV_DATE],[AD1],[AD2],[AD3],[AD4],[AD5],[AD6],[TERMS],[EXCHANGE_RATE],[CREATED_BY],[DATE_CREATED],[ZERO_RATED_INV],[TAX_INCLUDE],[Deleted],[SEAL_NO],JOB_NO,Inv_Amt,GST,Inv_Net,Status) values ('''+@INV_NO+''','''+@AC_NO+''','''+@AC_NAME+''','+CAST(@INV_DATE as varchar(50))+','''+@AD1+''','''+@AD2+''','''+@AD3+''','''+@AD4+''','''+@AD5+''','''+@AD6+''','''+@TERMS+''','''+CAST(@EXCHANGE_RATE as float)+''','''+@CREATED_BY+''','+CAST(@DATE_CREATED as varchar(50))+','+CAST(@ZERO_RATED_INV as CHAR(1))+','+CAST(@TAX_INCLUDE as CHAR(1))+','+CAST(@Deleted as CHAR(1))+','''+@SEAL_NO+''','''+@JOB_NO+''','+CAST(@Inv_Amt as decimal)+','+CAST(@GST as decimal)+','+CAST(@Inv_Net as decimal)+','''+@Status+''')'
exec(@sql)
end


I am doing my project in 3 tier I have taken Exchangerate field in BEL as float/decimal.

Would you Please resolve this error.
Posted
Comments
PIEBALDconsult 5-Jan-15 23:32pm    
Why the frack are you using dynamic SQL? You're just making things harder on yourself.

I guess, there is a column with datatype FLOAT in your table and you are inserting STRING data to that column.
You can format the script to make it more readable. You can use below online too.
poorsql
 
Share this answer
 
You are passing a varchar into a float field.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900