如何在此声明中使用GROUP BY
?
UPDATE LoanMaster
SET LeadsID1 = NEXT VALUE FOR LM
WHERE PrdAcctId IS NOT NULL
GROUP BY LBrCode, CustNo
答案 0 :(得分:0)
我将推测您需要LBrCode
和CustNo
对的唯一ID。你可以这样做:
with nums as (
SELECT t.*, (NEXT VALUE FOR LM) as newval
FROM (SELECT DISTINCT LBrCode, CustNo
FROM LoanMaster
WHERE PrdAcctId IS NOT NULL
) t
)
update lm
set LeadsId1 = newval
from LoanMaster lm JOIN
nums
on lm.LBrCode = nums.LBrCode and lm.CustNo = nums.CustNo;
注意:尽管这应该有效,但您应该创建一个Leads
表,每个值一行。看起来你想要一个外键关系,你应该有一个关系的实体。