--示例
CREATE PROCEDURE get_sales_for_title
@title varchar(80),   -- This is the input parameter.
@ytd_sales int OUTPUT -- This is the output parameter.
AS  -- Get the sales for the specified title and 
-- assign it to the output parameter.
SELECT @ytd_sales = ytd_sales
FROM titles
WHERE title = @titleRETURN
GO 

解决方案 »

  1.   

    晕,还没整完:
    下列程序用输入参数值执行存储过程,并将存储过程的输出值保存到调用程序的局部变量 @ytd_sales_for_title 中。-- Declare the variable to receive the output value of the procedure.
    DECLARE @ytd_sales_for_title int-- Execute the procedure with a title_id value
    -- and save the output value in a variable.EXECUTE get_sales_for_title
    "Sushi, Anyone?", @ytd_sales = @ytd_sales_for_title OUTPUT -- Display the value returned by the procedure.
    PRINT 'Sales for "Sushi, Anyone?": ' +    convert(varchar(6),@ytd_sales_for_title)
    GOSales for "Sushi, Anyone?": 4095
      

  2.   

    declare @sql nvarchar(1000)
    declare @count int
    declare @tbn   nvarchar(50)set @sql='select @count=count(*) from '+@tbnexec sp_executesql @sql,N'@count int output',@count outputselect @count
      

  3.   

    create procedure cr
    @crauthors cursor varying output
    as
    set @crauthors=cursor 
    for
    select * from authors
    open @crauthors
    --open crs
    --set @crauthors=crs
    go
    declare @crs cursor
    exec dbo.cr @crs output
      

  4.   

    create proc test
        @tablename varchar(20),  --表名
        @total int output        --返回值
    as
    begin
       declare @sqltext nvarchar(2000)
       set @sqltext='select @a=count(*) from '+@tablename  
       exec sp_executesql @sqltext,'@a int output',@total    --返回@total 
    end