CREATE PROCEDURE [dbo].[BillingCalculateInterview] @UserID int, @ProjectID int, @date1 datetime, @date2 datetime, @Count int = null output, @SuccessCount int = null outputAS-- проверяем чтобы даты не были больше текущейif (@date2 > GETDATE()) set @date2 = GETDATE()if (@date2 < @date1)begin set @count = null set @successcount = null returnendset nocount on-- считаемselect @count = count([ID]), @successcount = sum(case when [iv_IsSuccess] = 1 then 1 else 0 end)from [Billing] with (nolock)where (@userid is null or [UserID] = @userid) and (@projectid is null or [ProjectID] = @projectid) and [EventTypeID] = 20 and ([PeriodDT2] between @date1 and @date2)if (@count = 0) set @count = nullset nocount off