我在单个存储过程中有两个查询。我有一个表值参数和我用于两个查询的 TVP。我的一个查询工作正常(更新查询工作正常),但如果我使用相同的 TVP 进行插入查询,那么它不会向其中插入值。我不知道发生了什么并且错误也不会出现。
这是我的查询:
CREATE TYPE Mapping_n_Info_Master_Type AS TABLE
(
quantity INT,
product_id INT,
sell_order_no VARCHAR(20),
selling_product_id VARCHAR(20),
tax_id INT
);
GO
CREATE PROC spInsert_Rs_Sell_Order_Master
(
@tvp_Mapping_n_Info_Master Mapping_n_Info_Master_Type READONLY
)
AS
BEGIN
SET NOCOUNT ON
BEGIN TRY
BEGIN TRANSACTION
--Start This Part is not Working
INSERT INTO
RS_Sells_Invoice_Info_Master
SELECT
sell_order_no,product_id,selling_product_id,tax_id,qty
FROM
@tvp_Mapping_n_Info_Master
--End This Part is not Working
--Insert Logic For Sell Order Mapping
UPDATE
RS_Sell_Order_Mapping
SET
quantity = TVP.quantity
FROM
@tvp_Mapping_n_Info_Master tvp
INNER JOIN RS_Sell_Order_Mapping AS SOM ON
TVP.product_id = SOM.product_id AND TVP.sell_order_no = SOM.sell_order_no
WHERE
SOM.product_id = TVP.product_id
AND
SOM.sell_order_no = TVP.sell_order_no
COMMIT TRANSACTION
END TRY
BEGIN CATCH
DECLARE @ERROR_MSG NVARCHAR(MAX), @SEVERITY INT, @STATE INT
SELECT @SEVERITY = ERROR_SEVERITY(), @STATE = ERROR_STATE()
,@ERROR_MSG = ERROR_MESSAGE() + ' err src line: ' + CAST( ERROR_LINE() AS NVARCHAR(20)) + ' ' + ISNULL(ERROR_PROCEDURE(), '');
--@ERROR_MSG = ERROR_MESSAGE()
ROLLBACK;
-- RE-THROW EXCEPTION FOR DIAGNOSTIC VISIBILITY
RAISERROR (@ERROR_MSG ,@SEVERITY, @STATE);
RETURN
END CATCH
END
我的表看起来像这样
我是否要更改提供给插入查询的参数序列。请对此提出您的建议