gpt4 book ai didi

sql - T-SQL MERGE 与条件什么不匹配?

转载 作者:行者123 更新时间:2023-12-03 23:16:07 25 4
gpt4 key购买 nike

假设我做了一个与条件匹配的合并

MERGE TargetTable WITH(HOLDLOCK) AS target
USING SourceTable AS source
ON (target.ID = source.ID)
WHEN MATCHED AND (source.BitCondition = 0) THEN
UPDATE TargetTable
WHEN NOT MATCHED -- what is not matched??
INSERT INTO TargetTable

不匹配的只是记录不在两个表中还是像
NOT(MATCHED AND (source.BitCondition = 0))

注意我有意忽略匹配且 BitCondition = 1 的情况

最佳答案

NOT MATCHED 的默认值根据 MERGE documentationNOT MATCHED BY TARGET ,表示该行存在于源中但不存在于 MERGE 的目标中.

避免使用 source.BitCondition = 1 插入不匹配的行,您可以添加 AND健康)状况:

WHEN NOT MATCHED BY TARGET AND (source.BitCondition = 0) THEN
INSERT INTO TargetTable

关于sql - T-SQL MERGE 与条件什么不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50551764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com