Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting number of working hours
Message
De
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:
01618770
Vues:
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.
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform