Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting number of working hours
Message
From
20/04/2015 10:20:41
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01618554
Message ID:
01618770
Views:
33
>With that WHERE clause you filter first and last record from the example data.
>Maybe you need:
>
>WHERE (BusinessTime.Start>=@Start AND BusinessTime.Start<=@End) OR
>      (BusinessTime.[End]>=@Start AND BusinessTime.[End]<=@End)) Temp
>
Thanks, your approach is better. This would give this:
DECLARE @Start DATETIME
DECLARE @End DATETIME
 
SET @Start='2014-01-23 09:15:00'
SET @End='2014-01-29 13:45:00'
 
SELECT SUM(Temp.SecondValue)/3600 AS HourValue
FROM (SELECT CAST(DATEDIFF(SECOND,
 CASE WHEN BusinessTime.Start>@Start THEN BusinessTime.Start ELSE @Start END,
 CASE WHEN BusinessTime.[End]<@End THEN BusinessTime.[End] ELSE @End END) AS DECIMAL(10,2)) AS SecondValue
 FROM BusinessTime
 WHERE (BusinessTime.Start>=@Start AND BusinessTime.Start<=@End) OR
  (BusinessTime.[End]>=@Start AND BusinessTime.[End]<=@End)) Temp
However, this gives 35.5 not 31.5.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform