写了好半天的有史以来写过的最长的存储过程

费尽心里写了好半天的有史以来写过的最长的存储过程,不是什么机密的东西,贴在这里,以资纪念,:)
 1 None.gif CREATE   PROCEDURE  dbo.list_taoke    
 2 None.gif AS
 3 ExpandedBlockStart.gifContractedBlock.gif     /**/ /* SET NOCOUNT ON */  
 4 None.gif     delete   from  taokee_Temp
 5 None.gif    
 6 ExpandedBlockStart.gifContractedBlock.gif     declare   @uid   int ; /**/ /*用户ID*/
 7 ExpandedBlockStart.gifContractedBlock.gif     declare   @exp_count   decimal /**/ /*被淘的文章数量*/
 8 ExpandedBlockStart.gifContractedBlock.gif     declare   @persent   decimal  ; /**/ /*被淘率*/
 9 ExpandedBlockStart.gifContractedBlock.gif     declare   @info_count   decimal ; /**/ /*发布的文章数量*/
10 None.gif    
11 ExpandedBlockStart.gifContractedBlock.gif     /**/ /*以下循环*/
12 None.gif     declare   cursor_Userid  cursor    for
13 None.gif         select  author  from  info  where  (infolawid > 0 and  ( exp >= 2 group   by  author
14 None.gif     open  cursor_Userid
15 None.gif     begin
16 None.gif         FETCH   NEXT   FROM  cursor_Userid
17 None.gif         INTO   @uid
18 None.gif         WHILE   @@FETCH_STATUS   =   0
19 None.gif         BEGIN
20 None.gif             set   @exp_count = select   count ( * from  info  where  author = @uid   and   exp > 2 )
21 None.gif             set   @info_count   =  ( select   count ( * from  info  where  author = @uid  )
22 None.gif             set   @persent   =  ( @exp_count / @info_count ) * 100
23 None.gif             insert   into  taokee_Temp(uid,exp_count,persent,info_count)  values  ( @uid , @exp_count , @persent , @info_count )
24 None.gif             FETCH   NEXT   FROM  cursor_Userid
25 None.gif             INTO   @uid
26 None.gif         END
27 None.gif     end
28 None.gif     close  cursor_Userid
29 None.gif     deallocate  cursor_Userid    
30 None.gif     RETURN
31 None.gif
32 None.gif GO
33 None.gif


更新于: 2006年11月22日 下午
发现上面的存储过程可以被一句SQL取代,如下:
None.gif select   top   50   *   from  
None.gif
None.gif
select    distinct  author  as  uid ,info_count = ( select   count ( 0 from  info  where  info.author = t.author ),
None.gifexp_count
= ( select   count ( 0 from  info  where  info.author = t.author  and   exp > 2 )
None.gif 
from  info t  where  infolawid > 0   
None.gif
as  x  order   by  x.exp_count  desc
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值