Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
An update which does not finish
Message
 
 
À
20/04/2015 14:05:01
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:
01618799
Vues:
37
>>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.
>
>What would be the difference with this:
>
>
>UPDATE Client
> SET MyDate=
>  (SELECT COALESCE((SELECT TOP 1 Invoice.AddDate FROM Invoice
>  WHERE Invoice.NoClient=Client.Numero
>  ORDER BY Invoice.Numero DESC),'1899-12-30 00:00:00'))
>
>
>In that one, I also do a massive update where the inner select includes the relational of each update to be done (Client.Numero).
>
>This one works ok.

This is one to one relationship and in the other case it's not 1 to 1. But I would not write this UPDATE that same way also. I'd rather use CTE and ROW_NUMBER approach.

It's a bad idea to write UPDATE that way. Check out this blog post

Dear FROM clause...

This is one of my many favorites of his blogs.
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