2014-12-01 存储过程
---存储过程
alter proc ChaXun
as
begin
select *from Score
end
go
--执行
exec chaxun
--删除
drop proc chaxun
--输入参数的存储过程
alter proc jiayibai
@shuru int,
@canshu int
as
begin
print @shuru+@canshu
end
go
exec jiayibai 10,120
--是否闰年
create proc isRunNian
@year int
as
begin
if @year%4=0 and @year%100!=0
begin
print '是闰年'
end
else if @year%100=0 and @year%400=0
begin
print '是闰年'
end
else
begin
print '不是闰年'
end
end
go
declare @jieguo int
exec @jieguo=isRunNian 2100
print @jieguo
----一元二次方程存储过程
alter proc yiyuanerci
@a int,
@b int,
@c int
as
begin
if @a=0
begin
--print '不是一元二次方程'
return 1
end
else
begin
declare @sqrt decimal(18,2)
set @sqrt = @b*@b-4*@a*@c
if @sqrt>0
begin
--print '两个不同的根'
return 2
end
else if @sqrt=0
begin
--print '两个相同的根'
return 3
end
else
begin
--print '无解'
return 4
end
end
end
go
declare @fanhui int
exec @fanhui = yiyuanerci 0,4,3
if @fanhui=1
print '请仔细阅读一元二次方程的构造规则'
--out输出参数
alter proc outzhi
@shuru int,
@jiashi int output,
@jiaershi int output
as
begin
set @jiashi=@shuru+10
set @jiaershi=@shuru+20
return 1
end
go
declare @shuchu1 int,@shuchu2 int,@return int
exec @return=outzhi 15,@shuchu1 output,@shuchu2 output
print @shuchu1
print @shuchu2
print @return