Hi,
In project i'm currently developing, i'm using additional columns in database tables which has tree structure. Columns are named: TreePath and TreeLeveel. I'm using SQL Server and both columns are automatically filled using database triggers on insert or update.
TreePath column is used to store path to elements and TreeLevel is used to store depth of element in tree which in your case could look like this:
AgentCode IntroCode TreeLevel TreePath
A0001 0 .A0001.
A0002 A0001 1 .A0001.A0002.
A0003 A0001 1 .A0001.A0003.
A0004 A0003 2 .A0001.A0003.A0004
and so on...
In this case you don't have to use recursion and complicated queries to retrieve rercord with childs. So, if you want to get records for A0002 and all childs you can use simple select:
SELECT * FROM YOUR_TABLE_NAME WHERE TreePath LIKE '.A0002%'
I hope it help you :)