编辑:我把表结构和真正的MERGESQL服务器 - 错误MERGE
我想使用微软的SQLServer 2014年MERGE,但我的目标表得到一个语法错误:
MERGE VALORATION_DETAIL_INPUTS_LIMIT AS Target
USING (VALUES (922, 4098)) AS Source(idValoration, idDetValInput)
ON (Source.idValoration = Target.idValoration AND Source.idDetValInput = Target.idDetValInput)
WHEN MATCHED THEN
UPDATE SET idSubject = 1633, idGood = 1114, idWarranty = 7519, idSubWarranty = 7520, units = 1.000000,
unitPrice = 250.000000, limit = 250.000000, percTax = 21.000000, tax = 52.500000, subtotal = 197.500000,
total = 250.000000
WHEN NOT MATCHED BY TARGET THEN
INSERT (idDetValInput, idValoration, idSubject, idGood, idWarranty, idSubWarranty, units,
unitPrice, limit, percTax, tax, subtotal, total)
VALUES(4093, 922, 1633, 1114, 7519, 7520, 1.000000, 250.000000, 250.000000, 21.000000, 52.500000, 197.500000, 250.000000)
OUTPUT $ACTION
错误是:
Msg 156, Level 15, State 1, Line ...
Incorrect syntax near the word 'AS'.
表结构:
CREATE TABLE VALORATION_DETAIL_INPUTS_LIMIT
(
idDetValInput bigint NOT NULL,
idValoration bigint NOT NULL,
idSubject bigint NOT NULL,
idGood int NULL,
idWarranty int NULL,
idSubWarranty int NULL,
units real NULL,
unitPrice money NULL,
limit money NULL,
percTax real NULL,
tax money NULL,
subtotal money NULL,
total money NULL
)
你没有 “14号线” 在查询中。 –
那么,我有一个“使用”和一个“GO”之前。我认为这不是必须的。 –
现在,你的问题是不同的。 “INSERT语句中的列数多于VALUES子句中指定的值,VALUES子句中的值数量必须与INSERT语句中指定的列数相匹配。”所以,我所做的是在INSERT语句的VALUES部分末尾添加两个值,并且它工作正常。简而言之,在INSERT语句中指定的13列超过11个在INSERT语句的VALUES部分中提供的VALUES。还有2个需要提供的值。 – Amit