以下查询有效,但必须有更好的方法将表的值设置为两组数据联合的最大日期。这是我所拥有的:
Update stagingTable
Set OverrideFlag =
(
select total.overrideflag from
(
select Customer_SSN as ssn, RequestDateTime as maxdate, overrideflag
from tableA
where RequestDateTime > '9/1/2012'
union
select ssn, EntryDate as maxdate, overrideflag
from tableB
where EntryDate > '9/1/2012'
) total
join
(
select ssn, max(maxdate) as maxdate from
(
select Customer_SSN as ssn, RequestDateTime as maxdate
from tableA
where RequestDateTime > '9/1/2012'
union
select ssn, EntryDate as maxdate
from tableB
where EntryDate > '9/1/2012'
) maxs
group by ssn
) maxdates on total.ssn = maxdates.ssn and total.maxdate = maxdates.maxdate where total.ssn = stagingTable.ssn
)