以下是显示错误新with
关键字的存储过程:
下面为更新现有记录而编写的程序,如果json输入参数中不存在则删除记录,如果未找到匹配则插入。但是下面的问题甚至不能创建新的存储过程
CREATE PROCEDURE usp_PaymentRecommendationsInsertUpdate
@PaymentRecommendationsJson NVARCHAR(MAX)
AS
BEGIN
MERGE INTO PaymentRecommendations AS PR
USING (
SELECT ClaimId,
CoverageTypeId,
Payee,
IndemnityPmtRequestAmnt,
ExpensePaymentRequestAmnt,
RequestDate,
Memo,
CheckNumber,
IssueDate,
CreatedOn,
CreatedBy,
ModifiedOn,
ModifiedBy
FROM OPENJSON(@PaymentRecommendationsJson)
WITH (
ClaimId BIGINT,
CoverageTypeId SMALLINT,
Payee VARCHAR(256),
IndemnityPmtRequestAmnt MONEY,
ExpensePaymentRequestAmnt MONEY,
RequestDate DateTime,
Memo VARCHAR(512),
CheckNumber VARCHAR(16),
IssueDate DATETIME,
CreatedOn DATETIME,
CreatedBy BIGINT,
ModifiedOn DATETIME,
ModifiedBy BIGINT
)) AS InputJSON
ON (PR.ClaimId = InputJSON.ClaimId)
WHEN MATCHED THEN
UPDATE SET ClaimId = InputJSON.ClaimId,
CoverageTypeId = InputJSON.CoverageTypeId,
Payee = InputJSON.Payee,
IndemnityPmtRequestAmnt = InputJSON.IndemnityPmtRequestAmnt,
ExpensePaymentRequestAmnt = InputJSON.ExpensePaymentRequestAmnt,
RequestDate = InputJSON.RequestDate,
Memo = InputJSON.Memo,
CheckNumber = InputJSON.CheckNumber,
IssueDate = InputJSON.IssueDate,
CreatedOn = InputJSON.CreatedOn,
CreatedBy = InputJSON.CreatedBy,
ModifiedOn = InputJSON.ModifiedOn,
ModifiedBy = InputJSON.ModifiedBy
WHEN NOT MATCHED THEN
INSERT ( ClaimId,
CoverageTypeId,
Payee,
IndemnityPmtRequestAmnt,
ExpensePaymentRequestAmnt,
RequestDate,
Memo,
CheckNumber,
IssueDate,
CreatedOn,
CreatedBy,
ModifiedOn,
ModifiedBy)
VALUES ( InputJSON.ClaimId,
InputJSON.CoverageTypeId,
InputJSON.Payee,
InputJSON.IndemnityPmtRequestAmnt,
InputJSON.ExpensePaymentRequestAmnt,
InputJSON.RequestDate,
InputJSON.Memo,
InputJSON.CheckNumber,
InputJSON.IssueDate,
InputJSON.CreatedOn,
InputJSON.CreatedBy,
InputJSON.ModifiedOn,
InputJSON.ModifiedBy);
WHEN NOT MATCHED BY SOURCE THEN
DELETE
END
我们是否需要在azure数据库中以正常方式处理它?</ p>
答案 0 :(得分:1)
在你的proc结束时,在... InputJSON.ModifiedBy)*;*
之后删除分号,然后在最终DELETE
之后添加一个分号,如下所示:
CREATE PROCEDURE usp_PaymentRecommendationsInsertUpdate
@PaymentRecommendationsJson NVARCHAR(MAX)
AS
BEGIN
MERGE INTO PaymentRecommendations AS PR
USING (
SELECT ClaimId,
CoverageTypeId,
Payee,
IndemnityPmtRequestAmnt,
ExpensePaymentRequestAmnt,
RequestDate,
Memo,
CheckNumber,
IssueDate,
CreatedOn,
CreatedBy,
ModifiedOn,
ModifiedBy
FROM OPENJSON(@PaymentRecommendationsJson)
WITH (
ClaimId BIGINT,
CoverageTypeId SMALLINT,
Payee VARCHAR(256),
IndemnityPmtRequestAmnt MONEY,
ExpensePaymentRequestAmnt MONEY,
RequestDate DateTime,
Memo VARCHAR(512),
CheckNumber VARCHAR(16),
IssueDate DATETIME,
CreatedOn DATETIME,
CreatedBy BIGINT,
ModifiedOn DATETIME,
ModifiedBy BIGINT
)) AS InputJSON
ON (PR.ClaimId = InputJSON.ClaimId)
WHEN MATCHED THEN
UPDATE SET ClaimId = InputJSON.ClaimId,
CoverageTypeId = InputJSON.CoverageTypeId,
Payee = InputJSON.Payee,
IndemnityPmtRequestAmnt = InputJSON.IndemnityPmtRequestAmnt,
ExpensePaymentRequestAmnt = InputJSON.ExpensePaymentRequestAmnt,
RequestDate = InputJSON.RequestDate,
Memo = InputJSON.Memo,
CheckNumber = InputJSON.CheckNumber,
IssueDate = InputJSON.IssueDate,
CreatedOn = InputJSON.CreatedOn,
CreatedBy = InputJSON.CreatedBy,
ModifiedOn = InputJSON.ModifiedOn,
ModifiedBy = InputJSON.ModifiedBy
WHEN NOT MATCHED THEN
INSERT ( ClaimId,
CoverageTypeId,
Payee,
IndemnityPmtRequestAmnt,
ExpensePaymentRequestAmnt,
RequestDate,
Memo,
CheckNumber,
IssueDate,
CreatedOn,
CreatedBy,
ModifiedOn,
ModifiedBy)
VALUES ( InputJSON.ClaimId,
InputJSON.CoverageTypeId,
InputJSON.Payee,
InputJSON.IndemnityPmtRequestAmnt,
InputJSON.ExpensePaymentRequestAmnt,
InputJSON.RequestDate,
InputJSON.Memo,
InputJSON.CheckNumber,
InputJSON.IssueDate,
InputJSON.CreatedOn,
InputJSON.CreatedBy,
InputJSON.ModifiedOn,
InputJSON.ModifiedBy)
WHEN NOT MATCHED BY SOURCE THEN
DELETE;
END
MERGE语句必须以分号(;)
结束
您可能还在处理兼容性问题。将数据库兼容性设置为140,例如:
ALTER DATABASE yourDatabase SET COMPATIBILITY_LEVEL = 140;