我有以下查询来列出两个表的员工。
我需要将 a.staffdiscountstartdate 更新为“20100428”,如何为此重写以下查询?
select
a.employeeid,
b.employeeid
from
tblEmployees a
left join
tblCards b
on
a.employeeid=b.employeeid
where
GroupStartDate < '20100301'
and
StaffDiscountStartDate > '20100428'
and
datediff(day,groupstartdate,staffdiscountstartdate)>1
and
b.employeeid is null
最佳答案
应该能够做到:
UPDATE a
SET a.staffdiscountstartdate = '20100428'
from tblEmployees a
left join tblCards b on a.employeeid=b.employeeid
where GroupStartDate < '20100301'
and StaffDiscountStartDate > '20100428'
and datediff(day,groupstartdate,staffdiscountstartdate)>1
and b.employeeid is null
仅限 MS SQL。其他 SQL 版本不支持此语法。
关于选择查询的 SQL 更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2493881/