I am trying to add a where condition to be checked only if variable @schoolId is not null otherwise return all results. Please know that If condition cannot be used because it is a very large query. This is just a part of it.
Table Name - Students
Id Name SchoolId
1 John 6
2 Mark 6
3 Alice 12
4 Prince null
Query
Select * from Students st
where st.SchoolId = Case when @schoolId is not null then @schoolId else st.SchoolId End
So if @schoolId is null, I want to return all 4 rows. I want it to return results where SchoolId is null too if variable is null. Currently with above query it does not return 4th row