我正试图运行此更新语句(至少对我而言)。它应该非常简单,但我无法克服这个障碍。每次我尝试运行它时,都会抛出错误
第15行,第1行,第1行,第1行 关键字'其中'。
附近的语法不正确
我已经检查了所有的字段名称并且它们是有效的,并且我已经尽我所能来克服这个障碍,但是我被击败了。
update #holdingdata
set 1e2a3m = (select count(*)
from subtodom.blaize.dbo.sassafras
where employeename in (select ename
from subtodom.hr.dbo.employees
where status in ('Active')
and CAST(hiredate As Date) between 'Jan 13 2015 12:00AM' and 'Jan 115 2015 12:00AM')
where manager = 'Jeff'
答案 0 :(得分:2)
update #holdingdata
set 1e2a3m = (select count(*)
from subtodom.blaize.dbo.sassafras
where employeename in (select ename
from subtodom.hr.dbo.employees
where status in ('Active') )
and CAST(hiredate As Date) between 'Jan 13 2015 12:00AM' and 'Jan 115 2015 12:00AM')
where manager = 'Jeff'
答案 1 :(得分:0)
这会更容易被读作连接而不是两个子查询(希望仍能产生相同的结果吗?)
update #holdingdata
set 1e2a3m = (
select count(*)
from subtodom.blaize.dbo.sassafras blaize
INNER JOIN subtodom.hr.dbo.employees hr
ON( blaize.employeename = hr.ename )
WHERE hr.status = 'Active' AND
CAST(blaize.hiredate As Date) between 'Jan 13 2015 12:00AM'
and 'Jan 115 2015 12:00AM'
)
WHERE manager = 'Jeff'
也许还将count(*)替换为count(distinct blaize.employeename)