我的陈述:
MERGE INTO tblshoppingcart AS target USING
(SELECT * FROM tblshoppingcart
WHERE session_id = 'f7f2eb03-5ca5-4a85-b83e-70f197c087ae ' AND primlink = '19830625000054' AND store = 17 AND catalog = 'SS3' AND quantity = 35 AND item_type = 0) AS source
ON target.primlink = source.primlink AND
target.session_id = source.session_id AND target.item_type = source.item_type
WHEN NOT MATCHED THEN
INSERT VALUES ( 'f7f2eb03-5ca5-4a85-b83e-70f197c087ae', '19830625000054', 17, 'SS3', 'PAS', 35, 5, '', 0 )
WHEN MATCHED THEN
UPDATE SET quantity = 15
匹配时UPDATE工作正常
当NOT MATCHED时,INSERT不会抛出错误,但也不会插入任何内容。
答案 0 :(得分:1)
尝试更改当匹配时:
WHEN NOT MATCHED BY TARGET THEN
答案 1 :(得分:0)
谢谢,对于回复,我发现问题是我传递的是硬编码值,但是当我使用源/目标名称时,它就有效了。
而不是INSERT VALUES ( 'f7f2eb03-5ca5-4a85-b83e-70f197c087ae'
我做INSERT VALUES ( target.session