I am trying to write a stored procedure to assist with development of our database, but I am having some trouble using it. For example:
DECLARE @pID int;
SET @pID = 1;
EXEC WriteLog 'Component', 'Source', 'Could not find given id: ' + CAST(@pID AS varchar);
This yields the error (on SQL Server 2005):
Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '+'.
Can someone explain to me why my syntax is incorrect, and the right way to solve this problem?
Perhaps something like this?
You can't do operations on the parameters of a stored procedure. You should assign that value on another variable and then pass it to your SP.
DECLARE @id int
SET @id = 10
SELECT LTRIM(RTRIM(STR(@id))) AS stringValue
Use this code to print a Sql Server Error message:
Here is the result set.
Try this instead...