sql 存储过程返回值

1:return 返回一个值

CREATE PROCEDURE  testReturn
AS
return 145
GO

--查询分析器中调用
--DECLARE @RC int
--exec @RC=singleValue
--select @RC 

2:output 返回值
  CREATE   procedure   testoutput
  @p1   int,    
  @p2   int     output,
  @p3   int     output ,
  @p4   varchar(10)     output  

  as  
  select   @p2   =   @p1   *2
  select   @p3   =   @p1   *3
  select   @p4   =   'sfdsdfsdf'
GO

  --查询分析器中调用
  --declare @p2_output int
 -- execute testoutput 4,@p2_output output  
  --select @p2_output
 --====================================--
  --declare @p2_output int,@p3_output int
 -- execute testoutput 4,@p2_output output,@p3_output output
 -- select @p2_output,@p3_output


3:返回表
CREATE PROCEDURE tableTestsss

AS

declare @OrderShipperTab TABLE (col1 varchar(80),col2 varchar(80))
  INSERT @OrderShipperTab values('11','12')
  INSERT @OrderShipperTab values('21','22')
  INSERT @OrderShipperTab values('31','32')
  INSERT @OrderShipperTab values('42','42')
 select * from @OrderShipperTab
GO

  --查询分析器中调用
--Create Table #T (col1 varchar(10),col2 varchar(10))
--Insert #T exec tableTestsss
--Select * From #T
--drop table #T

 

你可能感兴趣的:(数据库)