Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Iterative Queryto retrieve data
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 10/11/2012 :  05:23:41  Show Profile  Reply with Quote

Please assume this . There are 4 Employees in a company. A,B,C,D

A is the reporting manger of B .
B is the reporting manger of C .
C is the reporting manger of D .

When A logins He can See all the sales info of B,C,D which is stored in other DB.
When B logins he can See all the sales info of C,D
When B logins he can See all the sales info of D

There is chance of adding number of employees in the given hierarchy .

So for getting the datas for A i have to run the same query with different conditions multiple times.

Is there any other method to do this. ?

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/11/2012 :  06:57:30  Show Profile  Reply with Quote
You can build a virtual table of all the employees in the organizational hierarchy using a recursive CTE and then join your sales table to this virtual table. Take a look at this page to see if that helps:
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000