I'm new to development. In sql I have written a stored procedure and it is working correctly but I just wanted to make sure it is done the correct way.
Here I am using an IF statement in sp to check whether date column in a table is NULL or not:
if ((select sdate
from tbla
where id='3') = Null)
begin
some query
end
Will this work for all cases or do I need to check for ''(empty) also?
In SQL null is not equal to anything, including other nulls. You need to use is null instead of the = operation.
Empty and NULL are not the same thing, so you will need to check for an empty string separately. You also should use is null rather than = null to check if a column is null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With