I have a stored procedure that I need to filter rows that have a binary value and return only rows that are not null in the binary column.
When I execute this stored procedure:
create procedure sp_GetGraduatingStudentDataByYear
(
@year nvarchar(4)
)
as
select * from Cohort_Graduation_Student_Data where Exp_Grad_Year = @year and Off_Track != null
go
I get no results.
How can I alter this script to return the rows with a null value in the binary column?
This is not because it’s a binary column, but because
nullin SQL should not be compared to anything. Essentially,Off_Track != nullcondition filters out all rows – all checks forcolumn = nullandcolumn != nullalways evaluate tofalse.Use
is not nullinstead: