CREATE PROCEDURE e_ifShowMsgAddUp
@msgserid int out,
@empid int,
@subject varchar(200),
@content text=null,
@readd bit,
@status int,
@bwrite bit,
@confremind bit,
@mobileRemind  bit,
@remindinf varchar(500),
@bsecret bit
 AS
--原有状态
declare @ostatus int if (@msgserid=0)
begin
insert oa.ioffice.dbo.ifShowMsg(empid,subject,content,readd,status,bwrite,confremind,mobileRemind,bsecret ) 
values(@empid,@subject,@content,@readd,@status,@bwrite,@confremind,@mobileRemind ,@bsecret)
set @msgserid=@@identity
end
else
begin
--原有状态
select @ostatus=status
from oa.ioffice.dbo.ifShowMsg
where msgserid=@msgserid --如果原有传阅状不是未发送,则不允许改变状态
if (@ostatus<>-1)
set @status=@ostatus update oa.ioffice.dbo.ifShowMsg set subject=@subject,content=@content,readd=@readd,status=@status,bwrite=@bwrite 
,confremind=@confremind,mobileRemind =@mobileRemind,bsecret=@bsecret
 where msgserid=@msgserid

--短信提醒
if (@status<>-1 and @mobileRemind=1)
begin
insert oa.ioffice.dbo.ifmobileinf(sendto,content,empid)
select b.mobile,@remindinf,l.empid 
from oa.ioffice.dbo.ifmsglabel l join oa.ioffice.dbo.mrbaseinf b on l.empid=b.empid
where l.MsgSerID=@msgserid and l.mobileReminded=0 and len(b.mobile)>10 
--将该传阅标志为已发短信提醒
update oa.ioffice.dbo.ifmsglabel set mobileReminded=1 where msgserid=@msgserid and mobilereminded=0
end if (@ostatus=-1 and @status<>-1)
begin
--系统提醒
set @remindinf='<a href=/ioffice/prg/if/showmsgaddup.aspx?closed=1&msgserid='+cast(@msgserid as varchar(10))+' target=_blank>'+@remindinf+'</a>'
insert oa.ioffice.dbo.ssremindinf(empid,content)
select empid,@remindinf
from oa.ioffice.dbo.ifmsglabel
where msgserid=@msgserid
end

endGO
CREATE  PROCEDURE e_ssRemainInfAdd
@empid int,
@content varchar(500)
 AS
insert oa.ioffice.dbo.ssRemindInf(empid,content) values(@empid,@content)
GO
然后我写了几个语句,但添加但没有成功,是不是@msgserid OUTPUT的原因?declare 
@P1 int,
@msgid int
select @msgid=max(msgserid)+1 from oa.ioffice.dbo.ifShowMsg
set @P1=@msgid
exec e_ifShowMsgAddUp @msgserid=@P1 output,@empid=476,@subject='ych传阅测试',@content='测试是否成功呢?',@readd = 1, @status = 0, @bwrite = 1, @confremind = 1, @mobileRemind  = 0, @remindinf = '你有新的传阅[ychych],来自余程辉。', @bsecret  = 0
go

解决方案 »

  1.   

    没仔细看试下:
    改存储过程代码
    if (@msgserid=0)
    --〉
    if (isnull(@msgserid,0)=0)测试代码:
    select @msgid=max(msgserid)+1 from oa.ioffice.dbo.ifShowMsg
    --〉
    select @msgid=isnull(max(msgserid),0)+1 from oa.ioffice.dbo.ifShowMsg
      

  2.   

    @msgserid int out, 如果是out的话,那有这个变量前面应该有returnif (@msgserid=0)
    begin
     insert...
    end但你这里却给它取值...把out去掉,其他地方没看仔细,太长了
      

  3.   

    @msgserid是输出用的,本身就没有值怎么还判断