I am trying to debug a stored procedure that I did not write. Specifically focused on the third line beginning with AND (Citation_Main.User_Defined5
, if I set a subset of records' User_Defined5 column to NULL, using an update query, then the stored procedure writes an export file that I am expecting. However, if the User_Defined5 field is set to 'N', a file is not written.
DECLARE Cit_Select_Cursor CURSOR FOR SELECT Citation_Main.Number,Citation_Main.Issue_Date,
Citation_Main.Issue_Time,Citation_Main.Officer_Comment1, Citation_Main.Officer_ID,
Citation_Main.Officer_Name,Citation_Main.License_Plate,Citation_Main.License_State,
Citation_Main.Location_Block,Citation_Main.Location_Street,Citation_Main.Location_Dir,
Citation_Main.Location_Suffix,Citation_Main.Amount_Due,Citation_Main.Meter,
Citation_Main.Make,Citation_Main.Color_Major,Citation_Main.Body_Style,
Citation_Main.License_Type,Citation_Main.VIN,Citation_Activity.ChargeCode,Citation_Activity.DebitAmount
,Citation_Main.Officer_Comment2
FROM Citation_Main --TTM_Bak
--ADDED 03/12/2016 Inner Join and check for void and warning
-- INNER JOIN Citation_Main On TTM_Bak.Number = Citation_Main.Number
INNER JOIN Citation_Activity On Citation_Main.Citation_Key = Citation_Activity.Citation_Key
Where --ExportViaDAT = 'N' And
Citation_Main.Void ='N' And Citation_Main.Warning ='N'
AND (Citation_Main.User_Defined5 ='N' or Citation_Main.User_Defined5 ='' or Citation_Main.User_Defined5 is NULL)
ORDER BY Citation_Main.Issue_Date DESC
I have been reading the suggested SO posts that appeared as I was entering this post, but could not see anything wrong with this part of the stored procedure.
My question is, is there something inherently wrong with checking for NULL in this part of the stored procedure?