CREATE PROCEDURE [dbo].[Products_GetRecordCountByCategoryID] ( @categoryID int ) AS BEGIN SET NOCOUNT ON; SELECT COUNT(*) AS RecordCount FROM [dbo].[Products] WHERE ([CategoryID] = @categoryID AND 1 = CASE WHEN @categoryID IS NULL THEN 0 ELSE 1 END) OR ([CategoryID] IS NULL AND 1 = CASE WHEN @categoryID IS NULL THEN 1 ELSE 0 END) END