本文介绍了如果给定的用户ID是团队领导,则显示向用户id报告的雇员,否则显示向给定用户id的团队负责人报告的雇员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 ))

推荐答案

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  ))


这篇关于如果给定的用户ID是团队领导,则显示向用户id报告的雇员,否则显示向给定用户id的团队负责人报告的雇员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 06:07