Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting number of working hours
Message
 
À
20/04/2015 10:20:41
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01618554
Message ID:
01618776
Vues:
30
>>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform