0

我有 2 个过程 procgetid,insertmarks.procgetid 返回一个 int 值,该值将在 insertmarks 过程中使用

code in procgetid procedure

ALTER procedure [dbo].[procgetid](@sid int output)
as  
begin
select @sid=(select isnull(max(id),0)+100 from test2);
return @sid
end

code in insertmarks procedure

ALTER procedure [dbo].[insertmarks](@sub1 int,@sub2 int,@sub3 int)
as 
declare @student_id int
begin
exec @student_id = procgetid
insert into marks values(@sub1,@sub2,@sub3,@student_id)
end 

执行 insertmarks 过程时出现错误“无法将值 NULL 插入到列‘student_id’,列不允许空值。插入失败。”

4

1 回答 1

3
ALTER procedure [dbo].[insertmarks](@sub1 int,@sub2 int,@sub3 int)
as 
declare @student_id int

开始 设置@student_id = exec [schemaname].procgetid
插入标记值(@sub1,@sub2,@sub3,@student_id) end

于 2013-04-03T11:45:36.063 回答