Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting number of working hours
Message
 
 
To
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:
01618778
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.

Use SUM (CAST(Temp.SecondValue as DECIMAL(22,2))) /3600
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform