Erro将varchar转换为float [英] Erro converting varchar to float
本文介绍了Erro将varchar转换为float的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个存储过程,需要一些参数。然后用它们用数据填充货币转换率表。
我的问题是在我的第二个sql命令的存储过程即将结束时。
如果我硬编码这样的值,该命令有效:
< pre> SELECT @ SQL2 ='update [dbo ]。[CurrencyTbl]设置'+ @ CurrencyName +'= 1 WHERE CurrencyName =''卢比'';'
但我希望使用用户为@Ropee,@ Euro等输入的值。
类似于:
SELECT @ SQL2 ='update [dbo]。 [CurrencyTbl]设置'+ @ CurrencyName +'='+ @Rupee +'CurrencyName =''卢比'';'
但是我得到了错误:
将数据类型varchar转换为float时出错。
我的代码可以在以下链接找到
我尝试过:
mydb,Sql Server - rextester [ ^ ]
解决方案
SELECT @ SQL2 ='update [dbo]。[CurrencyTbl] set'+ @ CurrencyName +'='+ convert(varchar(100),@ Rupe)+'WHERE CurrencyName =''Rupee''';
I have written a stored procedure which takes some paramters. These are then used to populate a currency conversion rate table with data.
My issue is near the end of the stored procedure with my 2nd sql command.
The command works if I hard code the value like this:
<pre>SELECT @SQL2 = 'update [dbo].[CurrencyTbl] set '+@CurrencyName+' = 1 WHERE CurrencyName = ''Rupee'';'
But i wish to use the values input by a user for @Rupee,@Euro etc.
Something like:
SELECT @SQL2 = 'update [dbo].[CurrencyTbl] set '+@CurrencyName+' = '+@Rupee+'CurrencyName = ''Rupee'';'
But I get the error:
Error converting data type varchar to float.
My code can be found at the below link
What I have tried:
mydb, Sql Server - rextester[^]
解决方案
SELECT @SQL2 = 'update [dbo].[CurrencyTbl] set '+@CurrencyName+' = ' + convert(varchar(100), @Rupee) + ' WHERE CurrencyName = ''Rupee''';
这篇关于Erro将varchar转换为float的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文