|
|
Question : Stored Procedure Integer Problem
|
|
I have a stored procedure that has two variables, one to hold a field and another to hold a value. The problem is that when I execute the code it tells me that there is a problem "converting the varchar value". This is the @intValue which is being passed an integer value but appears as a string to the DB engine. How can I change the @vchStatement below to let SQL know it is a variable value. I am sure this is something simple.
CREATE PROCEDURE Email_Update @intEmailID INT, @vchField VARCHAR(60), @intValue INT AS DECLARE @vchStatement VARCHAR(255) SELECT @vchStatement = 'UPDATE Email SET [' + @vchField + '] = ' + @intValue + ' WHERE EmailID=' + @intEmailID EXEC @vchStatement GO
|
Answer : Stored Procedure Integer Problem
|
|
further correction:
'UPDATE Email SET ' + @vchField + ' = ' + CAST(@intValue AS VARCHAR(60)) + ' WHERE EmailID = ' + CAST(@intEmailID AS VARCHAR(10))
needed to case the intEmailID also
|
|
|
|