My sql query is as follows
IF @StatusId = 10
BEGIN
SELECT
*
FROM
Risk AS R
INNER JOIN Statuses AS St ON R.Status_Id=St.Status_Id
WHERE
R.MitigationOwner = COALESCE(@MitigationOwner,R.MitigationOwner)
AND R.RiskFactor = COALESCE(@RiskFactor,R.RiskFactor)
AND R.RiskArea = COALESCE(@RiskArea,R.RiskArea)
AND R.AddedWhen BETWEEN
COALESCE(CONVERT(DATETIME, @StartDate+'00:00:00',120),R.AddedWhen) AND
COALESCE(CONVERT(DATETIME,@EndDate+'23:59:59',120),R.AddedWhen)
END
When I pass only status Id and all other variables are null, then records with NULL MitigationOwner or ModifiedDate are not displayed..
What is wrong in this query?
I believe that by ModifiedDate you meant R.AddedWhen
try this: