如果同一行中另一列的值等于临时表中的值,我试图将 1 添加到一列。下面是代码。当我从存储过程运行代码时,它会为每一列添加 1,而不仅仅是临时表中显示的那些。有人看到查询有什么问题吗?
DECLARE @LineTable TABLE (
TempLineNumber FLOAT)
INSERT @LineTable
SELECT DocumentNumber
FROM chargebackdetailtemptable
GROUP BY DocumentNumber
HAVING Count(*) > 1
UPDATE ChargebackDetailTempTable
SET LineNumber = (SELECT Max(LineNumber) + 1
FROM ChargebackDetailTempTable c
LEFT OUTER JOIN @LineTable c2
ON c.DocumentNumber = c2.TempLineNumber
WHERE c.DocumentNumber IS NOT NULL
AND c2.TempLineNumber IS NOT NULL)