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 2008 Forums
 Other SQL Server 2008 Topics
 Iterative Queryto retrieve data

Author  Topic 

itsvineethpv
Starting Member

1 Post

Posted - 2012-10-11 : 05:23:41
Hai,

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. ?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-11 : 06:57:30
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: http://msdn.microsoft.com/en-us/library/ms186243(v=sql.105).aspx
Go to Top of Page
   

- Advertisement -