Assume @Ref <> 0
in first condition. Therefore my code will not reach the declaration of @XYZ
(line 2).
I think it must raise an error in the second IF
because of @XZY
was not declared.
But I'm surprised that there is no error raised.
IF @Ref = 0
BEGIN
DECLARE @XYZ int
SELECT @XYZ = RISKGROUP
FROM POLCONT WITH (NOLOCK, NOWAIT)
WHERE CONT = 555
END
IF @RISKGROUP <> @XYZ
BEGIN
-- do something ...
END
For example.
In python it raises this error:
Error: local variable 'XYZ' referenced before assignment