Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

BIT Data Type set to Null not returning result set.

$
0
0

Hello!

What could be wrong with the Stored Procedure below? (Please note that this is just an illustration of what I want to achieve with the BIT data type)

CREATE PROCEDURE #TestingProc
(
        @StartDate  DATETIME
	  , @EndDate    DATETIME
	  , @Color      BIT = Null
)
AS
	BEGIN 
IF @Color = 0
     BEGIN
	 SELECT ProductID 
	      , Name 
	      , Color 
		  , ListPrice 
	 FROM Production.Product 
	 WHERE SellStartDate BETWEEN @StartDate AND @EndDate 
	 AND Color = 'Silver'
	 END 
ELSE IF @Color = 1
    BEGIN
	 SELECT ProductID 
	      , Name 
	      , Color 
		  , ListPrice 
	 FROM Production.Product 
	 WHERE SellStartDate BETWEEN @StartDate AND @EndDate 
	 AND Color IN ('Silver','Black','Red')
	 END 
ELSE IF @Color = Null
     BEGIN 
	 SELECT ProductID 
	      , Name 
	      , Color 
		  , ListPrice 
	 FROM Production.Product 
	 WHERE ModifiedDate BETWEEN @StartDate AND @EndDate 
	 AND Color NOT IN ('Silver','Black','Red')
	 END 

	END
GO


USE AdventureWorks2012

EXEC #TestingProc '20020101','20090101',0 -- returns result set EXEC #TestingProc '20020101','20090101',1 -- returns result set EXEC #TestingProc '20020101','20090101',Null -- returns no result set

The logic is that I want to be able to retrieve data back when the @Color parameter is set to Null. Why are data not returned in this case?

I anticipate your reply. Thank you.


Zionlite



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>