Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
vavs
Starting Member
24 Posts |
Posted - 2010-09-09 : 14:11:37
|
| I am using the while exists but I want to stop it when it reaches a condition.Here is the code/*while exists (select * from Lineage where Depth = 0 and OrigTag# is not null) update L set L.depth = P.depth + 1,L.Lineage = P.Lineage + L.TAG# + '/'from Lineage Linner join Lineage as P on (L.OrigTag# = P.Tag#)where P.Depth>=0and P.Lineage <> '0'and L.Depth = 0*/What I need to do is stop the processing when the P.Depth reaches 9How do I do that? |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-09-09 : 14:59:38
|
| OR (SELECT p.Depth FROM Lineage p WHERE OrigTag# is not null) = 9????What version of SQL Server are you using...Also post the DDL of your table, sample data and expected resultsYou'll get a better solution...not the one you are trying to sledgehammer thoughBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2010-09-10 : 03:41:28
|
| Hello,For example...WHILE EXISTS (select * from Lineage where Depth = 0 and OrigTag# is not null) AND NOT EXISTS (select * from Lineage where Depth = 9 and OrigTag# is not null)Best regards,Devart,SQL Server Tools:dbForge Schema ComparedbForge Data ComparedbForge Query Builder |
 |
|
|
|
|
|