Ok, this is not working.I changed some things as well and simplified it and it still won't work. To test, I set up a new query window with this: DECLARE @days INT DECLARE @type INT DECLARE @clientID INT SET @days = NULL SET @type = 4 SET @clientID = 17SELECT * FROM ImportAlert aWHERE ( (a.ClientID IS NULL OR a.ClientID = @clientID) AND (a.ImportTypeID IS NULL OR a.ImportTypeID = @type) --AND (DATEDIFF(day, a.CompletedDate, GETDATE()) <= @days OR @days IS NULL) ) AND a.CompleteStatus = 1
I commented out the DATEDIFF for now just to test the other two.Above how it is returns 8 rows.If I set @type = NULL, it returns 0, yes, ZERO rows when it should return 8 rows as well.And just for more info, here is the full sproc:CREATE PROCEDURE dbo.pcGet_ImportAlertSearch @days INT = NULL, @type INT = NULL, @clientID INT = NULLASBEGIN SET NOCOUNT ON SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED SELECT a.ImportAlertID, a.ClientID, b.ImportType, a.ProcessedBy, c.Name, a.ProcessDate, a.CompleteStatus, a.CompletedBy, a.CompletedDate FROM ImportAlert a INNER JOIN ImportType b ON a.ImportTypeID = b.ImportTypeID INNER JOIN Client c ON a.ClientID = c.pk_idWHERE ( (a.ClientID IS NULL OR a.ClientID = @clientID) AND (a.ImportTypeID IS NULL OR a.ImportTypeID = @type) AND (DATEDIFF(day, a.CompletedDate, GETDATE()) <= @days OR @days IS NULL) ) AND a.CompleteStatus = 1 ORDER BY a.CompletedDate SET TRANSACTION ISOLATION LEVEL READ COMMITTED SET NOCOUNT OFF