SQL Querying Null Parameters
I was having problems with querying null parameters, mainly because of the syntax. For instance, I have a query:
select * from MyTable where NullParameter = @Param and OtherParameter = @OtherParam
But I didn't get any results. When I attempted this:
select * from MyTable where isnull(NullParameter, '') = isnull(@Param, '') and OtherParameter = @OtherParam
it worked. Essentially, I brought the parameters to the same level when they were null. I suspect it's because you have to use the is keyword whenever you reference null. So, doing this works. Any more knowledgable SQL developers want to provide a better solution, please do so in the comments.