从sqlserver中的另一个过程调用过程

时间:2013-04-03 07:17:25

标签: stored-procedures

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

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',列不允许空值.INSERT失败。”

1 个答案:

答案 0 :(得分: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)    结束