Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting number of working hours
Message
From
20/04/2015 11:01:31
 
 
To
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:
01618776
Views:
32
>>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.

Change SUM(Temp.SecondValue)/3600 to SUM(Temp.SecondValue)/3600.0
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform