如果给定的用户ID是团队领导,则显示向用户id报告的雇员,否则显示向给定用户id的团队负责人报告的雇员 [英] display employes who report to the user id given if user id given is team lead , else display the employes who report to the given user id's team lead

查看:43
本文介绍了如果给定的用户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 ))

推荐答案

试试这段代码。



Try this code.

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的团队负责人报告的雇员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆