Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
An update which does not finish
Message
 
 
To
20/04/2015 14:05:01
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01618796
Message ID:
01618799
Views:
38
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform