hollyx
hollyx

Reputation: 99

can not compare a datetime variable in sql-server to null value

I want to convert a datetime variable in SQL-Server to string and compare it with an empty string:

CONVERT(varchar(20), @DATEDEB, 1) =''

This is the test I have in my code:

IF (@N_CATComp = 4) AND (@EXON='' OR CONVERT(varchar(20), @DATEDEB, 1) ='' OR CONVERT(varchar(20), @DATEFIN, 1) = '') 

the test works even if datedeb and datefin empty

Upvotes: 0

Views: 972

Answers (2)

hollyx
hollyx

Reputation: 99

OKay , the answer is in sql-server, @DATEDEB<>'01/01/1900' which is the defult date that sqlç-serveur takes

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172468

If you want to compare the dates to NULL then you can simply try to use the IS [NOT] NULL

Determines whether a specified expression is NULL.

Something like

@myDate IS NULL AND @myDate1 IS NOT NULL

By using this you don't have to convert your datetime to a string variable.

Upvotes: 2

Related Questions