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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 while statement

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 L
inner join Lineage as P on (L.OrigTag# = P.Tag#)
where P.Depth>=0
and P.Lineage <> '0'
and L.Depth = 0
*/

What I need to do is stop the processing when the P.Depth reaches 9

How 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 results

You'll get a better solution...not the one you are trying to sledgehammer though

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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 Compare
dbForge Data Compare
dbForge Query Builder
Go to Top of Page
   

- Advertisement -