zoukankan      html  css  js  c++  java
  • 存储过程

    1. 一个简单存储过程例子
    2. CREATE PROCEDURE sp_cpsum_bylevel1 AS  
    3. begin  
    4.     declare @code varchar(50)  
    5.     declare @num varchar(50)  
    6.     declare @command varchar(1000)  
    7.     declare cursor_tmp_1 cursor for select left(ypcode,2),count(left(ypcode,2)) from cpname where ylevel=3  group by left(ypcode,2)  
    8.     open cursor_tmp_1  
    9.     fetch next from cursor_tmp_1 into @code, @num  
    10.     while @@fetch_status = 0  
    11.     begin     
    12.         set @command = 'update cpname set shuliang ='''+ @num + ''' where ycode ='''+ @code +''' and ylevel=1'  
    13.         print @command  
    14.         EXEC (@command)  
    15.         fetch next from cursor_tmp_1 into @code, @num         
    16.     end   
    17.     close cursor_tmp_1    
    18.     deallocate cursor_tmp_1  
    19. end  
    20.   
    21. GO  
    22. 执行 exec sp_cpsum_bylevel1 
  • 相关阅读:
    01_计算机基础
    09_哈希表
    08_查找算法
    Swagger使用
    Thymeleaf代码实例
    Spring boot代码实例
    Spring mvc代码实例
    Hibernate代码实例
    Mysql JDBC代码实例
    Mybatis代码实例
  • 原文地址:https://www.cnblogs.com/beijingstruggle/p/4904880.html
Copyright © 2011-2022 走看看