Sqlserver 存储过程的创建 以及调用 执行存储过程
存储过程分为:1.有参存储过程 2.无参存储过程
go
use Pro
create table ProWage
(
id int primary key identity,
PName char(10),
Wage int
)
insert into ProWage values('wangz',3000)
insert into ProWage values('wa',1000)
--创建不带参数的存储过程
go
create procedure FxWage
as
DECLARE @ProWageCount int
DECLARE @DBCount int
DECLARE @MoneyCount int
select @ProWageCount = count(*) from ProWage
select @DBCount = count(*) from ProWage where Wage > 2000
print '本次所加金额' + convert(varchar(6), @MoneyCount)
while (@DBCount <= @ProWageCount / 2)
begin
update ProWage set Wage = Wage + 100
@MoneyCount = @MoneyCount + 100
select @ProWageCount = count(*) from ProWage
select @DBCount = count(*) from ProWage where Wage > 2000
print '本次所加金额' + convert(varchar(6), @MoneyCount)
if (@DBCount > @ProWageCount / 2)
begin
break
end
end
go
--调用不带参数的存储过程
exec FxWage--执行存储过程