この問題に時間を費やしすぎて、目がくらんでしまったような気がします...そして、新鮮な目が単純なエラーを指摘するのに役立つことを願っています!
これは私がうまくいくと思うMERGE
ステートメントです:
動作していません:
MERGE assignment_tbl AS target
USING (SELECT 1 s) AS source
ON target.id = @id
AND target.id1 = @id1
AND target.id2 = @id2
WHEN matched AND NOT (target.iFeeScope = @iFeeScope OR target.nFeeAmount = @nFeeAmount) AND (target.bActive = 1) THEN
UPDATE SET target.dLastUpdated = @dNow,
target.dDisabled = @dNow,
target.bActive = 0;
問題は私のWHEN matched AND NOT
文にあります: (target.iFeeScope = @iFeeScope OR target.nFeeAmount = @nFeeAmount)
、これを回避する唯一の方法は、文を2つの別々の(そしてほぼ同一の)ブロックに分割することです:
作業中 (ただし非効率的):
MERGE assignment_tbl AS target
USING (SELECT 1 s) AS source
ON target.id = @id
AND target.id1 = @id1
AND target.id2 = @id2
WHEN matched AND NOT (target.iFeeScope = @iFeeScope) AND (target.bActive = 1) THEN
UPDATE SET target.dLastUpdated = @dNow,
target.dDisabled = @dNow,
target.bActive = 0;
MERGE assignment_tbl AS target
USING (SELECT 1 s) AS source
ON target.id = @id
AND target.id1 = @id1
AND target.id2 = @id2
WHEN matched AND NOT (target.nFeeAmount = @nFeeAmount) AND (target.bActive = 1) THEN
UPDATE SET target.dLastUpdated = @dNow,
target.dDisabled = @dNow,
target.bActive = 0;
次の 2 つのステートメントの結果を得るには、元のステートメントで何を変更する必要がありますか?
よろしくお願いします!