仅当存在较早的插入日期时,我才尝试更新表InsertDate
中所有不同的AccId
和AccNameHolder
组合的。#tmpResults
表模式是这样的:
#tmpResults
Trans | AccId | AccountNameHolder | EarlyDate | CardType
位置集合
Id | AccId | InsertDate | BtchId
卡错误
AccId | AccNameHolder | BtchId | TransId
这是我到目前为止所尝试的:
UPDATE RES
SET EarlyDate = pc.InsertDate
FROM ( dbo.PositionCollection pc
LEFT JOIN dbo.CardErrors ce ON ce.BtchId = pc.BtchId AND pc.id = ce.Transid )
INNER JOIN #tmpResults RES
ON RES.AccId = pc.AccId
AND RES.AccNameHolder = ce.AccNameHolder
WHERE RES.EarlyDate = (SELECT MIN(InsertDate) FROM PostionCollection)
AND RES.AccId = pc.AccId
AND RES.AccNameHolder = ce.AccNameHolder