use pubs
go
create proc prcgreater
@pub_id char(4)
@price money output,
@pubdate datetime output
as 
begin
select @price=price,@pubdate=pubdate
from titles
where pub_id=@pub_id
endcreate proc prcgq
@pub_id char(4)
as 
begin 
declare @price money 
declare @pubdate datetime
exec prcgreater @pub_id ,@price output,@pubdate output
if @@error<>0
begin  
   print 'error'
end
else
begin  
   select @price as price,@pubdate as pubdate
end   
endexec prcgq 'BU1111' --这个号是存在的,为什么不显示@price,@pubdate

解决方案 »

  1.   

    exec prcgq 'BU1111'  <------------ @pub_id char(4)它的长度不对吧??!
      

  2.   

    output的应该是参数,要放在参数声明那里,而不是过程体内,1
    服务器: 消息 266,级别 16,状态 2,过程 prcgreater,行 65535
    EXECUTE 后的事务计数指出缺少了 COMMIT 或 ROLLBACK TRANSACTION 语句。原计数 = 0,当前计数 = 1。
    error
    服务器: 消息 266,级别 16,状态 2,过程 prcgq,行 65535
    EXECUTE 后的事务计数指出缺少了 COMMIT 或 ROLLBACK TRANSACTION 语句。原计数 = 0,当前计数 = 1。
    是因为你的
    select @price=price,@pubdate=pubdate from titles output where pub_id=@pub_id
    的错误,
    改成扬兄那样就对了!
      

  3.   

    不能在过程体内使用output来表示输出的,应该在存储过程的参数列表中声明。可以采用Yang_(扬帆破浪)的方法,也可以定义一个临时表,如下:
    use pubs
    go
    create proc prcgreater
    @pub_id char(4)
    as 
    begin
    DECLARE @price money,
            @pubdate datetimecreat table #temptable
    (price money,
     pubdate datetime)select @price=price,@pubdate=pubdate
    from titles
    where pub_id=@pub_id
    insert into #temptable(price,pubdate)
      values(@price,@pubdate)
    endcreate proc prcgq
    @pub_id char(4)
    as 
    begin 
    declare @price money 
    declare @pubdate datetimecreat table #temptable
    (price money,
     pubdate datetime)insert exec prcgreater @pub_id if @@error<>0
    begin  
       print 'error'
    end
    else
    begin  
       select * from #temptable
    end   
    end