Hi:
We have the ability to execute stored procs from the middle-tier. Basically, in a database table called "SQLJobStep" we have -- among other things -- a varchar(300) column called "StoredProcedure" which holds something like this:
usp_SendReminderEmails @Debug=0, @LoginID
Via the middle-tier, a user clicks on a link to run the proc of their choice. What happens in the backend is a proc ("usp_SQLJobsActionGet") looks up the correct value from the "SQLJobStep.StoredProcedure" column and executes the value above.
This is the part of the code from "usp_SQLJobsActionGet" that executes the above value:
DECLARE @StepId int
DECLARE @LoginID varchar(12)
DECLARE @StoredProcedure varchar(300)
SET @StepId = 74
SET @LoginID = 'Yoav'
SELECT @StoredProcedure = SJS.StoredProcedure
FROM SQLJobStep AS SJS
WHERE SJS.StepId = @StepId
SET @StoredProcedure = ISNULL(@StoredProcedure, '')
IF CHARINDEX('@LoginID', @StoredProcedure) > 0
BEGIN
SET @LoginID = ISNULL(@LoginID, 'UNKNOWN')
SET @StoredProcedure = REPLACE(@StoredProcedure, '@LoginID', '@LoginID = ''' + @LoginID + '''')
END
IF @StoredProcedure != ''
BEGIN
EXEC(@StoredProcedure)
END
Fairly simple stuff....
The above code converts the original value to (and then executes):
usp_SendReminderEmails @Debug=0, @LoginID = 'Yoav'
Here is the issue:
When executing the "usp_SendReminderEmails @Debug=0, @LoginID = 'Yoav'" value nothing happens. No error is returned to the middle-tier. But I know that a value is pulled from the SQLJobStep table because we have other stored procedure values that get pulled and they run fine. (Note that the other values only have the @LoginID parameter, while this has @Debug=0 as well.)
At the same time, if I run the code above (both the gutted code and calling "usp_SQLJobsActionGet" directly) in SQL Management Studio, it works perfectly.
Do you have any advice? I am sure I am missing something very basic.
Thanks.