Reputation: 99
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
Reputation: 99
OKay , the answer is in sql-server, @DATEDEB<>'01/01/1900' which is the defult date that sqlç-serveur takes
Upvotes: 0
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