Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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[^]
Posted
Updated 18-May-17 3:04am

1 solution

SELECT @SQL2 = 'update [dbo].[CurrencyTbl] set '+@CurrencyName+' = ' + convert(varchar(100), @Rupee) + ' WHERE CurrencyName = ''Rupee''';
 
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