>ALTER FUNCTION [dbo].[GetPreCertStatus] >( > -- Add the parameters for the function here > @Start Datetime, > @End Datetime, > @DayLimit Int >) >RETURNS TABLE >AS >RETURN >( > -- Add the SELECT statement with parameter references here >with cte as (select case > when @Start IS NOT NULL and @End IS NOT NULL > THEN 'Settled' > WHEN @Start IS NOT NULL and @End IS NULL > then case when @DayLimit < (SELECT COUNT(*) FROM dbo.Calendar > WHERE isWeekday = 1 > AND isHoliday = 0 > AND dt >= cast(@Start as date) AND dt < cast(GETDATE() as date)) > THEN 'Overdue' > else > 'Pending' > END > ELSE -- what else is not covered ? > 'Pending' > END as StatusDescr) > >select StatusDescr, case StatusDescr WHEN 'Settled' then 2 when 'Pending' then 1 when 'Overdue' then 3 end as [Status] >from cte >) >>
declare @Start Datetime = '2017-01-19 09:04:53', @End Datetime = '2017-01-23 09:03:01', @DayLimit Int = 2 select calchours = (datediff(second, @Start, @End) / 3600 ,(SELECT COUNT(*) FROM dbo.Calendar WHERE isWeekday = 1 AND isHoliday = 0 AND dt >= cast(@Start as date) AND dt < cast(@End as date)) * 24But why don't I get 95.97 (rounded to 2 decimals) for the calchours? My result is just 95.
round(cast(datediff(second, @Start, @End) as float) / 3600, 2)