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             --      

 

posted on 2016-01-17 11:28  打不死的奥特曼  阅读(553)  评论(0编辑  收藏  举报