if exists(select * from sysobjects where name='sp_Queue')
drop procedure sp_Queue
go
create procedure sp_Queue
@uid int,
@cid int,
@time bigint,
@type int,
@msg varchar (10) output  --0 存在记录 1 不存在记录。写入数据库,2 存在记录。请求退出上次排队
as
declare
@ct int
select @ct=count(*) from [queue] where cid=@cid and uid=@uid
if(@ct>0)
begin
if(@type=0)
begin
delete from [queue] where  uid=@uid
select @msg='2'
end
else
select @msg='0'
end
else
begin
insert into [queue] (cid,uid,[time]) values(@cid,@uid,@time)
select @msg='1'
end
godeclare @msg varchar (10)
exec sp_Queue @uid=21,@cid=38,@time=1385843695,@type=1,@msg output,
select @msg
go大家看看这里那里错了啊。参数我都传了还报错。头晕了

解决方案 »

  1.   


    declare @msg varchar (10)
    exec sp_Queue @uid=21,@cid=38,@time=1385843695,@type=1,@msg = output
    select @msg
    go
      

  2.   

    --方法1
    declare @msgout varchar (10)
    exec sp_Queue @uid=21,@cid=38,@time=1385843695,@type=1,@msg=@msgout output -- @par=value 就要全部这样写
    select @msgout
    go--方法2
    declare @msgout varchar (10)
    exec sp_Queue 21,38,1385843695,1,@msgout output -- 或缺略,严格按照参数定义的顺序, 方法1命名参数可以乱序
    select @msgout
    go
      

  3.   


    exec sp_Queue @uid=21,@cid=38,@time=1385843695,@type=1,@msg output这句有问题 好像是要这样exec sp_Queue 21,38,1385843695,1,@msg output
      

  4.   


    declare @msg varchar (10)
    exec sp_Queue 21,38,1385843695,1,@msg output
    select @msg
    试一试这个
      

  5.   

    学习了 以前老是用 @msgout=@msg output 也总是提出@msg未声明 原来是写反了
      

  6.   


    呵呵,其实外面那个变量没必要改@msgout,@msg也行,我改了就是想显示这个顺序用的:
    @msg=@msg output
    这个很让人费解,不过毫无问题。
      

  7.   

    --把所有的
    select @msg='2'
    select @msg='1'
    select @msg='0'
     --改成
    set @msg='2'
    set  @msg='1'
    set @msg='2'--可能赋值不成功!
      

  8.   

     --OUTPUT 变量必须在创建表和使用该变量时都进行定义。
    --参数名和变量名不一定要匹配,不过数据类型和参数位置必须匹配exec sp_Queue 21,38,1385843695,1,@msg output
      

  9.   

    报错是:服务器: 消息 119,级别 15,状态 1,行 5
    必须传递参数个数 5,并以 '@name = value' 的形式传递后续的参数。一旦使用了 '@name = value' 形式之后,所有后续的参数就必须以 '@name = value' 的形式传递。