I have the following stored procedure.
ALTER PROCEDURE [dbo].[spList_Report]
@id INT,
@startDate DATETIME = NULL,
@endDate DATETIME = NULL,
@includeStatus1 BIT,
@includeStatus2 BIT,
@includeStatus3 BIT,
@includeStatus4 BIT
AS
SET NOCOUNT ON
SELECT *
FROM
tblProducts as products
WHERE
product.intID = @id
AND product.dateMain >= @startDate
AND product.dateMain <= @endDate
If @startDate AND @endDate are both null then I want it to return the rows ignoring the date check in the where clause.
How?
This should do
ISNULLyields the second value, if the first value is null.Thus:
if
@startDateis null, thendateMainmust be bigger than 0 (1900-01-01)if
@endDateis null, thendateMainmust be smaller thandateMain + 1 day