SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

itsvineethpv
Starting Member

India
1 Posts

Posted - 10/11/2012 :  05:23:41  Show Profile  Reply with Quote
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
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: http://msdn.microsoft.com/en-us/library/ms186243(v=sql.105).aspx
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.14 seconds. Powered By: Snitz Forums 2000