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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Proceedures

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-24 : 09:21:50
Gary writes "Hi,

I'm a bit of a lightweight when it comes to SQL Server, so please forgive my lack of knowledge....

Basically I have a 2 field table with employees and their immediate manager - something along the lines of A reports to B, B reports to C, C reports to D, and so on.

What I want to do is loop through all the records building a single string reporting structure such as ABCDEF.

I've got it all figured out in my head, but that doesn't translate too well to my keyboard !!!

Pass the first value,
Read the second field,
append the secon field to strReportStructure,
Loop back to the start passing the second field value as the first value.

Any help would be greatly appreciated - I've spent all day on this and the nearest I can get is the last record using a WHILE LOOP. The sp should terminate when both the 1st and 2nd fields have the same value (ie z reports to z)."
   

- Advertisement -