I have been trying to debug some questionable database transactions produced by a trigger and when stepping through the T-SQL have encountered unexpected results. After obtaining values from the cursor via FETCH NEXT FROM Updated_Cursor , I enter a while loop and then for each row fetched from the cursor I evaluate two variables to determine whether an insertion will be made after some processing as follows:
WHILE @@FETCH_STATUS = 0
BEGIN
IF (@first_indicator > 0 AND @second_indicator >0)
BEGIN
--processing and insert occurs here
In debug mode, stepping through the code, I can see that when the value of @first_indicator=1 and @second_indicator=0 this condition is evaluating to true which does not make sense to me. It is resulting in duplicate and erroneous rows being inserted. The two variables are bit datatype, which I feel may be relevant, but I am lost as to why this is happening.
When pulling your code out of the cursor like so:
It works as expected and does not print. Are you sure that you are looking at the right variables at the right time when the if statement gets executed?
Also, the two
IFstatements you mention in your comment are not equivalent. Therefore I am not exactly sure what your actual question is.