'The value assigned here is never used' - but it is
Ozzie
Posts: 50 Bronze 5
I have a SQL Pattern which SQL Prompt shreds a incorrect - here is an outline of the code. As you can see - the two variables are assigned, used and returned. Any idea why the SQL Prompt thinks the value assigned is not used?
BEGIN
DECLARE -- User Friendly Constants
@Failed BIT = 1,
@Succeeded BIT = 0; -- This will say 'The value assigned here is never used'
DECLARE -- Derived Constants
@ExecutionStatus INT = @Succeeded;-- This will say 'The value assigned here is never used'
BEGIN TRY
...Code
END TRY
BEGIN CATCH
-- Handle the Error
SET @ExecutionStatus = @Failed; -- so if we fail - we are changing the value
EXECUTE dbo.usp_LogErrorInfo;
END CATCH
RETURN @ExecutionStatus; -- so we are either using the initially assigned value or the value assigned in the try/catch block
END
BEGIN
DECLARE -- User Friendly Constants
@Failed BIT = 1,
@Succeeded BIT = 0; -- This will say 'The value assigned here is never used'
DECLARE -- Derived Constants
@ExecutionStatus INT = @Succeeded;-- This will say 'The value assigned here is never used'
BEGIN TRY
...Code
END TRY
BEGIN CATCH
-- Handle the Error
SET @ExecutionStatus = @Failed; -- so if we fail - we are changing the value
EXECUTE dbo.usp_LogErrorInfo;
END CATCH
RETURN @ExecutionStatus; -- so we are either using the initially assigned value or the value assigned in the try/catch block
END
Comments
Thanks for your post, I can recreate the issue here and I'll look into a fix now. I think Prompt is (wrongly) assuming that the catch statement is going to be hit every time.
Thanks,
Aaron.
Hopefully that fixes it for you, but if not just let me know!
Thanks,
Aaron.
Ozzie