Что вам нужно сделать, это включить OR
условие для проверки NULL
таких параметров:
DECLARE @BI_ResponsibleID INT , @CategoryID INT , @ChangeRequestorID INT
SET @BI_ResponsibleID = 5
SET @CategoryID = 3
SET @ChangeRequestorID = 4
SELECT TOP 4
[BI_ResponsibleID],
[CategoryID],
[ChangeRequestorID]
FROM [BI_Planning].[dbo].[tlbActivity]
WHERE
(BI_ResponsibleID = @BI_ResponsibleID OR @BI_ResponsibleID IS NULL)
AND (CategoryID = @CategoryID OR @CategoryID IS NULL)
AND (ChangeRequestorID = @ChangeRequestorID OR @ChangeRequestorID IS NULL)
Вы можете сделать это через сохраненный процесс, например:
CREATE PROCEDURE MyProcName
@BI_ResponsibleID = NULL
@CategoryID = NULL
@ChangeRequestorID = NULL
AS
SELECT TOP 4
[BI_ResponsibleID],
[CategoryID],
[ChangeRequestorID]
FROM [BI_Planning].[dbo].[tlbActivity]
WHERE
(BI_ResponsibleID = @BI_ResponsibleID OR @BI_ResponsibleID IS NULL)
AND (CategoryID = @CategoryID OR @CategoryID IS NULL)
AND (ChangeRequestorID = @ChangeRequestorID OR @ChangeRequestorID IS NULL)
END