我正在尝试从具有FK约束的不同表中检索标识列到桥表中。此查询有什么问题阻止了ID的显示?我需要先将这些ID插入返回变量或表中,然后再将其插入表中吗?
这是我编写的代码,存储过程成功完成,但是没有输出。
预期结果应该是输出桥表中的所有ID。
DECLARE @Registration_ID INT
DECLARE @Batch_ID INT
DECLARE @CheckResult_ID INT
DECLARE @CheckDetail_ID INT
DECLARE @OutputData TABLE
(Registration_ID INT,
Batch_ID INT,
CheckResult_ID INT,
CheckDetail_ID INT)
INSERT INTO [PTC].CheckResult_CheckDetail (Registration_ID, Batch_ID, CheckResult_ID, CheckDetail_ID)
OUTPUT INSERTED.Registration_ID, INSERTED.Batch_ID, INSERTED.CheckResult_ID, INSERTED.CheckDetail_ID
INTO @OutputData
(Registration_ID,Batch_ID,CheckResult_ID,CheckDetail_ID )
VALUES (@Registration_ID, @Batch_ID, @CheckResult_ID,@CheckDetail_ID)
-- View the inserted data
SELECT @Registration_ID = Registration_ID, @Batch_ID = Batch_ID, @CheckResult_ID = CheckResult_ID , @CheckDetail_ID = CheckDetail_ID
FROM @OutputData
任何建议都会有很大帮助!
谢谢! 安德里亚