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.
| Author |
Topic |
|
senthilavs
Starting Member
5 Posts |
Posted - 2012-03-07 : 03:06:50
|
| Hi,I want to find the approval level person id by passing current login person id. Form the below records "Kumaran", "Ramalingam" and "Senthil" are the approval person.Approval Level: "Karthik" --> "Senthil" --> "Ramalingam" --> "Kumaran"Eg:1. "Karthik" and "Sanmugam" are users. Both of them reporting to "Senthil".2. "Senthil" is reporting to "Ramalingam". Also once "Senthil" is approved the "Ramalingam" can view the "Senthil" approvals.3. "Ramalingam" is reporting to "Kumaran". Also once "Ramalingam" is approved the "Kumaran" can view the "Ramalingam" approvals.My Query Requirement.1. If "Kumaran" login to the System he need "Ramalingam" id to check the leave approved by "Ramalingam".2. If "Ramalingam" login to the System he need "Senthil" id to check the leave approved by "Senthil".DECLARE @_StaffID INTSET @_StaffID = 1 --KumaranSET @_StaffID = 2 --RamalingamSET @_StaffID = 3 --SenthilCREATE TABLE #ReportingToPerson (Staff_ID INT,Staff_Name VARCHAR(50),Reporting_To_ID INT)INSERT INTO #ReportingToPerson VALUES (1, 'Kumaran', NULL)INSERT INTO #ReportingToPerson VALUES (2, 'Ramalingam', 1)INSERT INTO #ReportingToPerson VALUES (3, 'Senthil', 2)INSERT INTO #ReportingToPerson VALUES (4, 'Karthik', 3)INSERT INTO #ReportingToPerson VALUES (5, 'Sanmugam', 3)INSERT INTO #ReportingToPerson VALUES (6, 'Ashok', 2)SELECT ReportTo.Staff_ID, ReportTo.Staff_Name, ReportTo.Reporting_To_IDFROM #ReportingToPerson LoggedIDINNER JOIN #ReportingToPerson AS ReportTo ON LoggedID.Staff_ID = ReportTo.Reporting_To_IDWHERE LoggedID.Staff_ID = @_StaffIDDROP TABLE #ReportingToPersonThanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|
|