我有一种感觉,我在这个问题上花了太多时间并且被蒙蔽了......希望一双新鲜的眼睛可以帮助指出一个简单的错误!
这是我认为应该起作用的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)
,我发现解决这个问题的唯一方法是将声明分成两个单独的(并且几乎相同的)块:
工作(但效率低下):
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;
我需要在我的原始语句中进行哪些更改才能达到以下两个语句的结果?
谢谢大家!