I’m not sure how to make this happen. We’re debugging an issue and we need to know if it’s possible for @@Error to be non-zero if the insert succeeds. We have a stored procedure that exits if @Error <> 0. And if we knew the answer to this, that would help. Anyone know?
The code is below. We want to know if it’s possible to get to the goto statement if the insert succeeded.
-- This happened
insert into Workflow
(SubID, ProcessID, LineID, ReadTime)
values
(@sub_id, @proc_id, @line_id, @read_time)
set @error = @@Error
set @insertedWorkflowId = SCOPE_IDENTITY()
if @error <> 0
begin
set @error_desc = 'insert into tw_workflow'
goto ERROR_EXIT
end
-- This didn't happen
INSERT INTO Master.WorkflowEventProcessing (WorkflowId, SubId, ReadTime, ProcessId, LineId) VALUES (@insertedWorkflowId, @sub_id, @read_time, @proc_id, @line_id)
INSERT INTO Master.ProcessLogging (ProcessCode, WorkflowId, SubId, EventTime) VALUES (10, @insertedWorkflowId, @sub_id, GETDATE())
EDIT
Maybe a better way to say what’s wrong is this: The first insert happened but the last two didn’t. How is that possible? Maybe the last two inserts simply just failed?
If this insert succeeds then there will be a non-zero @@rowcount since you’re simply using
values(rather than aselect...wherewhich could “successfully” insert 0 rows). You could use this to write some debug checks in there, or just include it as part of the routine for good.UPDATE
If a trigger fires on insert, an error in the trigger with severity of:
I arrived at this by adding a trigger to the workflow table and testing various values for severity, so I can’t readily say this would be the exact case in all environments:
Soooo, after that, we have somewhat of an answer to this question:
Yes…BUT, I’m not sure if there is another chain of events that could lead to this, and I’m not creative enough to put together the tests to prove such. Hopefully someone else knows for sure.
I know this all isn’t a great answer, but it’s too big for a comment, and I thought it might help!