November 6, 2006 at 11:58 am
In my stored proc, I'm trying to set/pass a datetime variable to NULL. Then I want to check if that variable is NULL. if yes then do A else do B. For some reason even though the value of the variable appears to be NULL it's evaluting the the NULL as false.
here's my code
spTest (@currentDate datetime, @BegDate datetime=NULL, @EndDate datetime =NULL)
If @BegDate=NULL
Select * From TableA Where EntryDate Between @BegDate and @EndDate
Else
Select * From TableA Where EntryDate Between @CurrentDate and @EndDate
any ideas?
sam
November 6, 2006 at 12:17 pm
CREATE PROC spTest (@currentDate datetime, @BegDate datetime=NULL, @EndDate datetime =NULL) AS
If @BegDate IS NULL
Select * From TableA Where EntryDate Between @BegDate and @EndDate
Else
Select * From TableA Where EntryDate Between @CurrentDate and @EndDate
November 6, 2006 at 12:22 pm
Try this:
DECLARE @BegDate datetime
SET @BegDate = NULL
IF @BegDate = NULL
PRINT 'NULL equals NULL'
IF @BegDate IS NULL
PRINT 'NULL IS NULL'
ELSE IF ISNULL( @BegDate, '01/01/1900') = '01/01/1900'
PRINT 'NULL does not equal NULL'
Did not see SQL ORACLE's post. This basically shows you that NULL does not equal NULL.
I wasn't born stupid - I had to study.
November 6, 2006 at 12:59 pm
it worked
thank u
sam
November 7, 2006 at 10:24 am
From BOL
When SET ANSI_NULLS is OFF, the Equals (=) and Not Equal To [<>] comparison operators do not follow the SQL-92 standard. A SELECT statement using WHERE column_name = NULL returns the rows with null values in column_name
December 1, 2019 at 3:02 pm
It didn't work
Thx
sam
First of all, that's an Oracle error. Oracle and SQL Server haven a whole lot of differences. PL/SQL <> T-SQL. Let's hope that whoever "SQL Oracle" is, also knows Oracle instead of just claiming to be an "oracle" at SQL.
Second, there are multiple answers on this thread. You need to post the code that caused the error.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply