Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
An update which does not finish
Message
 
 
À
20/04/2015 13:23:43
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01618796
Message ID:
01618797
Vues:
42
>This morning, we ended up with a successful approach to calculate the number of working hours between two dates, based on a table which contains working shifts.
>
>When executing the command, it went ok.
>
>Now, I included that select into an update so I can update all the records of the table.
>
>This went as follow:
>
>
>UPDATE Client
> SET DayBetweenFirstDateSecondDate=
>  (SELECT SUM(Temp.SecondValue)/3600.0/8 AS HourValue
>  FROM (SELECT DATEDIFF(SECOND,
>   CASE WHEN BusinessTime.Start>Client.FirstDate THEN BusinessTime.Start ELSE Client.FirstDate END,
>   CASE WHEN BusinessTime.[End]<Client.SecondDate THEN BusinessTime.[End] ELSE Client.SecondDate END) AS SecondValue
>   FROM BusinessTime
>   WHERE BusinessTime.NoProvince=84 AND BusinessTime.NoHoliday=0 AND 
>    ((BusinessTime.Start>=Client.FirstDate AND BusinessTime.Start<=Client.SecondDate) OR
>    (BusinessTime.[End]>=Client.FirstDate AND BusinessTime.[End]<=Client.SecondDate))) Temp)
>
>
>If I would have executed this in code, it would have taken approximately 10 to 20 minutes.
>
>So, the goal to build it all in one command was to target at optimization.
>
>However, this type of select does not seem to fit well with the update. The command never finishes. This has been running for two hours. I am trying to determine what is causing this.
>
>I had expected this one to complete in 3 to 5 minutes.

This is weird UPDATE statement. I suggest to start from the SELECT with JOIN into a temp table and see how long that SELECT will work.

If the select finishes in reasonable time, then still keep the temp table approach and just do UPDATE after the select based on PK.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform