• SQL IF while 游标


     1 -- if语句使用示例  
     2 
     3             declare @a int  
     4             set @a=1
     5             if @a>100  
     6                begin  
     7                    print @a =@a+1 
     8                end  
     9             else  
    10                begin  
    11                    print 'noooo'  
    12                end  
    13 
    14 
    15   -- while语句使用示例  
    16     declare @i int 
    17 set @i=1 
    18 while @i<30 
    19    begin 
    20    insert into test (userid) values(@i) 
    21    set @i=@i+1 
    22 end
    23 
    24 -- 设置重复执行 SQL 语句或语句块的条件。只要指定的条件为真,就重复执行语句。可以使用 BREAK 和 CONTINUE 关键字在循环内部控制 WHILE 循环中语句的执行。 本条为以前从网上查找获取!
    25 
    26 
    27  --   临时表和try
    28    
    29       -- 增加临时表  
    30        select * into #csj_temp from csj  
    31           
    32        -- 删除临时表 用到try  
    33         begin try    -- 检测代码开始  
    34              drop table #csj_temp  
    35         end try  
    36    
    37         begin catch  -- 错误开始  
    38         end catch 
    39 
    40  --- 游标循环读记录 
    41 declare @temp_temp int  
    42             --declare @Cur_Name  
    43             --@Cur_Name="aaa"  
    44             --------------------------------- 创建游标  --Local(本地游标)  
    45             DECLARE aaa CURSOR for select House_Id from House_House where Deleted=0 or deleted is null  
    46             ----------------------------------- 打开游标  
    47               Open aaa  
    48             ----------------------------------- 遍历和获取游标  
    49                  
    50             fetch next from aaa into @temp_temp  
    51             --print @temp_temp  
    52             while @@fetch_status=0  
    53             begin  
    54               --做你要做的事    
    55               select * from House_monthEnd where House_Id=@temp_temp  
    56    
    57               fetch next from aaa into @temp_temp  -- 取值赋给变量  
    58    
    59              --   
    60             end  
    61    
    62             ----------------------------------- 关闭游标  
    63               Close aaa  
    64             ----------------------------------- 删除游标  
    65               Deallocate aaa  
    66             --      
     1 -- if语句使用示例  
     2 
     3             declare @a int  
     4             set @a=12  
     5             if @a>100  
     6                begin  
     7                    print @a  
     8                end  
     9             else  
    10                begin  
    11                    print 'no'  
    12                end  
    13 
    14 
    15   -- while语句使用示例  
    16     declare @i int 
    17 set @i=1 
    18 while @i<30 
    19    begin 
    20    insert into test (userid) values(@i) 
    21    set @i=@i+1 
    22 end
    23 
    24 -- 设置重复执行 SQL 语句或语句块的条件。只要指定的条件为真,就重复执行语句。可以使用 BREAK 和 CONTINUE 关键字在循环内部控制 WHILE 循环中语句的执行。 本条为以前从网上查找获取!
    25 
    26 
    27  --   临时表和try
    28    
    29       -- 增加临时表  
    30        select * into #csj_temp from csj  
    31           
    32        -- 删除临时表 用到try  
    33         begin try    -- 检测代码开始  
    34              drop table #csj_temp  
    35         end try  
    36    
    37         begin catch  -- 错误开始  
    38         end catch 
    39 
    40  --- 游标循环读记录 
    41 declare @temp_temp int  
    42             --declare @Cur_Name  
    43             --@Cur_Name="aaa"  
    44             --------------------------------- 创建游标  --Local(本地游标)  
    45             DECLARE aaa CURSOR for select House_Id from House_House where Deleted=0 or deleted is null  
    46             ----------------------------------- 打开游标  
    47               Open aaa  
    48             ----------------------------------- 遍历和获取游标  
    49                  
    50             fetch next from aaa into @temp_temp  
    51             --print @temp_temp  
    52             while @@fetch_status=0  
    53             begin  
    54               --做你要做的事    
    55               select * from House_monthEnd where House_Id=@temp_temp  
    56    
    57               fetch next from aaa into @temp_temp  -- 取值赋给变量  
    58    
    59              --   
    60             end  
    61    
    62             ----------------------------------- 关闭游标  
    63               Close aaa  
    64             ----------------------------------- 删除游标  
    65               Deallocate aaa  
    66             --      
  • 相关阅读:
    poj 1084 Brainman(归并排序)
    Poj 2299 Ultra-QuickSort(归并排序)
    poj 1068 Parencodings(栈)
    Poj 2499 Binary Tree(贪心)
    Poj 2255 Tree Recovery(二叉搜索树)
    poj 2021 Relative Relatives(暴力)
    Poj 2092 Grandpa is Famous(基数排序)
    解决UMeditor上传图片失败
    解决使用了属性overflow:scroll、overflow-y:scroll、overflow-x:scroll;的网页在iPhone iOS Safari浏览器中滑动不流畅问题
    Kindeditor上传图片报错
  • 原文地址:https://www.cnblogs.com/goodge/p/5136969.html
Copyright © 2020-2023  润新知