Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
An update which does not finish
Message
De
20/04/2015 13:23:43
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
An update which does not finish
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01618796
Message ID:
01618796
Vues:
60
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.
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform