存储过程

 --创建存储过程 指定返回值
 CREATE PROCEDURE  testReturn
 AS
 return 145
 GO
 --执行存储过程
 DECLARE @RC int
 exec @RC=testReturn
 select @RC 
 
 --带输入参数的存储过程(存储过程语句中含有return)
 create procedure test_daican
  @username varchar(100),--用户名    
  @age int,--年龄
  @gender varchar(100)--性别
 as
 if(@username = '' or @username is null)--判断用户名是否为空
   return 1
 else
   begin
    insert into Student(username,age,gender) values(@username,@age,@gender)
    return 0
   end
   
 --调用
 
  declare @count int 
  exec @count = test_daican '',2,'123456' 
  select @count
  --
  declare @count int 
  exec @count = test_daican '赵子龙',2,'' 
  select @count


--3.带输出参数的存储过程(存储过程中可以有return可以没有return)
---创建存储过程
 create procedure sp_output
  @output int output--表示输出参数
 as
  set @output = 121
  return 1
  
  --调用
  declare @out int
  exec sp_output @out output --输出
  select @out
  
  
原文地址:https://www.cnblogs.com/yangxinghua/p/3673567.html