If I have a query that compares two dates in SQL Server, what will happen if one of the dates is null? -
if have query has clause like:
where date1 > date2 what happen if date2 null? need specify date1 , date2 both not null?
the types date()
it try compare date1 null , evaluate unknown.
where '2013-07-18' > null is unknown. see blog post on null behavior in 3 valued logic.
you want use function isnull around date2 or explicitly write out logic. using isnull prevent index being used, however. write:
where (date1 > date2 or date2 null)
Comments
Post a Comment