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
 General SQL Server Forums
 New to SQL Server Programming
 Advice about SQL Script

Author  Topic 

mmalaka
Starting Member

33 Posts

Posted - 2008-07-11 : 05:36:10
Experts,

I am looking for the best option to do the following:

We have 2 Tables: Managers Tables and Employee Tables
We have a LookUp Table which include a field for the ManagerID and a field of EmployeeID.


1- The user will select a record from the Manager tables to get the Manager Details and use the ManagerID to get all the EmplyeeIDs for the ManagerID

select EmployeeID from LookUP where ManagerID = var

2- the the system will use the EmplyeeIDs to query the Emplyee Table to get the details of the Emplyees

So the final result would be the deteails of the selected Manager and the details for all the Employee related to that manager

How to create a Stored Procedure to do this?

Thanks in Advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-11 : 06:54:27
Do you want this recursively? If yes, you could use a recursive CTE to achieve this if you're using sql 2005:-
http://msdn.microsoft.com/en-us/library/ms186243.aspx
Go to Top of Page

mmalaka
Starting Member

33 Posts

Posted - 2008-07-11 : 07:23:49
Yes I do this everytime the user slect a record in the manager table

I am using SQL 2000
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-12 : 02:08:08
Probably this is what you're looking at:-

http://support.microsoft.com/kb/248915
Go to Top of Page
   

- Advertisement -