Mitesh Oswal (9/4/2012)
Hi ,Can you please try the below logic
I did and, as expected, it contains a triangular join. Please see the following article for why that will be absolutely devestating to the server for larger rowcounts.
http://www.sqlservercentral.com/articles/T-SQL/61539/
Either use a Quirky Update, a recursive CTE that doesn't use a Triangular Join, or use a well formed static, forward only, read only cursor. It'll be a lot faster and a whole lot easier on recources than almost anything (there is an exception but don't have time to find it right now) that uses a Triangular Join.
--Jeff Moden
Change is inevitable... Change for the better is not.