我有这个插入语句
CREATE PROCEDURE s_Add$Subject
(@SubjectName varchar(50),
@TheSubjectID int OUT)
AS
INSERT INTO [Subject] (SubjectName)
VALUES (@SubjectName)
SET @TheSubjectID = @@IDENTITY
我不记得曾经发生过这种情况,但由于输出参数是输出,为什么要调用id来传递?然后我尝试将@TheSubjectID
作为声明的变量并且它抛出一个错误,我将其设置为
declare @TheSubjectID int out
它导致错误,因为它说int的语法不正确。哦,请不要抨击我使用@@IDENTITY
而不是SCOPE_IDENTITY
,我更喜欢@@IDENTITY
,并且从未遇到过任何问题。 :)
答案 0 :(得分:0)
试试这个
CREATE PROCEDURE s_Add$Subject (
@SubjectName varchar(50),
@TheSubjectID int = NULL OUT)
AS
INSERT INTO [Subject] (SubjectName)
VALUES (@SubjectName)
SET @TheSubjectID = @@IDENTITY