我正在使用两个表emp
和AM_ActionItems
表的结构是
emp
表
AM_ActionItems
表
除了AssignedBy = AssignedTo = userid
select *
from (select *
from AM_ActionItems as amp
where amp.DueDate > convert(date, dateadd(day, 0, getdate()))
and amp.DueDate <= convert(date, dateadd(day, +1, getdate()))
and amp.closeddate is null) as emp_det
left outer join
emp on AssignedBy = userid
子查询正在运行
结果是
AssignedBy AssignedTo AssignedDate DueDate closeddate
Ponne.trichy Syed Jameel Pasha 2014-03-27 2014-04-02 NULL
VenkatBiroje Rekha 2014-03-28 2014-04-02 NULL
问题是
assignedby = assignedto = userid
表格中的 emp
如何从emp
表中获取所有列?
答案 0 :(得分:0)
我认为这个查询会给你答案。
select emp.*
from tbl_emp emp left join AM_ActionItems amp
emp.userid=amp.assignedto self join AM_ActionItems amp1
amp.assignedto =amp1.assignedto
where amp.DueDate > convert(date, dateadd(day, 0, getdate()))
and amp.DueDate <= convert(date, dateadd(day, +1, getdate()))
and amp.closeddate is null
答案 1 :(得分:0)
您想要选择内部查询结果的分配者或受让人的所有用户?然后从emp中选择并使用EXISTS查找是否可以找到匹配的记录。
select *
from emp
where exists
(
select *
from AM_ActionItems as amp
where emp.empid in (AssignedBy, AssignedTo)
and amp.DueDate > convert(date, dateadd(day, 0, getdate()))
and amp.DueDate <= convert(date, dateadd(day, +1, getdate()))
and amp.closeddate is null
);