Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting number of working hours
Message
From
20/04/2015 10:05:22
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01618554
Message ID:
01618769
Views:
29
After verification, the WHERE clause need to be like this so to include in the record set the minimum and maximum values:
DECLARE @Start DATETIME
DECLARE @End DATETIME
DECLARE @Start2 DATETIME
DECLARE @End2 DATETIME
 
SET @Start='2014-01-23 09:15:00'
SET @End='2014-01-29 13:16:00'
SET @Start2='2014-01-23 08:00:00'
SET @End2='2014-01-29 17:00:00'
 
SELECT SUM(Temp.SecondValue)/3600 AS HourValue
FROM (SELECT 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 SecondValue
 FROM BusinessTime
 WHERE BusinessTime.NoProvince=84 AND
  BusinessTime.Start>=@Start2 AND BusinessTime.Start<=@End2 AND
  BusinessTime.[End]>=@Start2 AND BusinessTime.[End]<=@End2) Temp
However, the /3600 rounds the value. I need to find a way to collect the decimals.
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