Some examples of procudure of Sqlserver 2000

I have read SQL server 2000 stored procedures HandBook,just do some easy examples of it.here is the code:

create procedure Example_05 @ValIn bigint,@ValOut bigint output
as
begin
  if @ValIn > 20
  begin
     print 'Invalid starting point should be <=20'
     return -99
  end
  
  declare @WorkValIn bigint, @WorkValOut bigint
  
  if @ValIn != 1
     begin
       set @WorkValIn = @ValIn -1
       print @@NESTLEVEL
       exec Example_05 @WorkValIn,@WorkValOut output
       set @ValOut = @WorkValOut * @ValIn
     end
  else
    set @ValOut = 1
end

declare @FactIn int,@FactOut int
set @FactIn =6
exec Example_05 @FactIn,@FactOut output
print 'Factorial of ' + convert(varchar(3),@FactIn) +' is '+convert(varchar(20),@FactOut)

 

create procedure Example_03
as
begin
  declare @var1 int,@var2 int
  set  @var1 = 1
  set  @var2 = 1
  while @var1 <10
    begin
      if @var2>20
         break
      set @var1 = @var1+1
      set @var2 = @var2+@var2
    end
   print 'var1='+convert(char(5),@var1) +'and var2='+convert(char(5),@var2)
end

 

create procedure example_02
as
begin
  select product_id,mfr_id,qty_on_hand,
  case  qty_on_hand
  when 0 then 'No qty'
  when (select max(qty_on_hand) from [products]) then 'top qty'
  else 'aver qty'
  end as disc
  from [products]
end

 I will learn it more :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值