Click here to Skip to main content
15,922,407 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
declare @teamLead as int
select @teamLead=Report_To from TM_USER where TM_UserID=106

(select distinct emp.TM_UserID,emp.FullName,TL.FullName as TeamLead from TM_User EMP
join TM_User TL on emp.Report_To=tl.TM_UserID where ( emp.Report_To=@teamLead or emp.TM_UserID=@teamLead ))
Posted
Comments
Member 10256268 6-Sep-13 4:08am    
give full code

1 solution

Try this code.

SQL
declare @teamLead as int
declare @eid int

select @eid = 4

select @teamLead=TM_UserID from TM_USER where Report_To=@eid

if @teamLead is null
begin
    select @teamLead=Report_To from TM_USER where TM_UserID=@eid
end
else
begin
    select @teamLead=@eid
end


(select distinct emp.TM_UserID,emp.FullName,TL.FullName as TeamLead from TM_User EMP
join TM_User TL on emp.Report_To=tl.TM_UserID where ( emp.Report_To=@teamLead  ))
 
Share this answer
 
Comments
Member 10256268 6-Sep-13 5:29am    
its working thank u ArunRajendra
ArunRajendra 6-Sep-13 5:31am    
Can you please vote the solution ;)?
Member 10256268 6-Sep-13 5:36am    
sorry i want to vote 5 how to do it
Member 10256268 6-Sep-13 5:35am    
sorry i want to vote 5 how to do it
ArunRajendra 6-Sep-13 7:26am    
click on 5th star.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900