I am very new to SQL Server Stored Procedures, This is My SP :
CREATE PROCEDURE [dbo].[spGetBonusRunDetails]
(
@StartDate as DATETIME,
@EndDate as DATETIME,
@PageNumber int,
@PageSize int,
@Status int
)
AS
;WITH DataCTE AS
(
SELECT ROW_NUMBER() OVER(Order by Id) as RowNumber
,[StartDateTime]
,[EndDate]
,[Status]
,[ExecutionTime]
,[Code] , TotalRows = Count(*) OVER()
FROM [dbo].[BonusRun]
WHERE ((StartDateTime BETWEEN @StartDate AND @EndDate)
OR (EndDate BETWEEN @StartDate AND @EndDate))
AND (Status = @Status)
)
I want that @Status condition check sometimes not to be included in WHERE clause.
How to do that ?
Edit :
is it not possible to to write some thing
IF @Status <= 0
then @Status = NULL
END IF
and in where statement
AND (Status = @Status OR @Status IS NULL)