SqlServer中循环和条件语句示例!
来源:互联网 发布:mips linux gnu gcc 编辑:程序博客网 时间:2024/05/18 12:33
- -- ╔════════╗
- -- =============================== ║ if语句使用示例 ║
- -- ╚════════╝
- declare @a int
- set @a=12
- if @a>100
- begin
- print @a
- end
- else
- begin
- print 'no'
- end
- -- ╔══════════╗
- -- =============================== ║ while语句使用示例 ║
- -- ╚══════════╝
- declare @i int
- set @i=1
- while @i<30
- begin
- insert into test (userid) values(@i)
- set @i=@i+1
- end
- -- 设置重复执行 SQL 语句或语句块的条件。只要指定的条件为真,就重复执行语句。可以使用 BREAK 和 CONTINUE 关键字在循环内部控制 WHILE 循环中语句的执行。 本条为以前从网上查找获取!
- -- ╔════════╗
- -- ================================ ║ 临时表和try ║
- -- ╚════════╝
- -- 增加临时表
- select * into #csj_temp from csj
- -- 删除临时表 用到try
- begin try -- 检测代码开始
- drop table #csj_temp
- end try
- begin catch -- 错误开始
- end catch
- -- ╔═════════╗
- -- =============================== ║ 游标循环读记录 ║
- -- ╚═════════╝
- declare @temp_temp int
- --declare @Cur_Name
- --@Cur_Name="aaa"
- --------------------------------- 创建游标 --Local(本地游标)
- DECLARE aaa CURSOR for select House_Id from House_House where Deleted=0 or deleted is null
- ----------------------------------- 打开游标
- Open aaa
- ----------------------------------- 遍历和获取游标
- fetch next from aaa into @temp_temp
- --print @temp_temp
- while @@fetch_status=0
- begin
- --做你要做的事
- select * from House_monthEnd where House_Id=@temp_temp
- fetch next from aaa into @temp_temp -- 取值赋给变量
- --
- end
- ----------------------------------- 关闭游标
- Close aaa
- ----------------------------------- 删除游标
- Deallocate aaa
- --
阅读全文
0 0
- SqlServer中循环和条件语句示例!
- SqlServer中循环和条件语句示例!
- 条件语句和循环
- 条件语句和循环
- 循环和条件语句
- 条件语句和循环语句
- Python 条件语句和循环
- 条件,循环和其他语句
- Python中条件选择和循环语句使用方法介绍
- shell中的循环语句和条件语句
- Python条件语句和循环语句
- Go 语言条件语句和循环语句
- Swift - 条件语句和循环语句
- JavaScript_2th_条件语句和循环语句
- Python 条件语句和循环语句
- Python条件语句和循环语句
- 【python】条件语句和循环语句
- python条件语句和循环语句简介
- 智能充电桩——为电动汽车的最后一米铺路!
- [leetcode]41. First Missing Positive(Java)
- 写两个线程,其中一个线程打印1-52,另一个打印A-Z,打印顺序为12A34B56C....5152Z
- 一道常被人轻视的前端JS面试题
- Cron表达式
- SqlServer中循环和条件语句示例!
- Uploadify 3.2 参数属性、事件、方法函数详解
- cocoa touch
- 【数据库-SQL Server】IDispatch error #3092
- 第一次使用Android Studio时你应该知道的一切配置(二):新建一个属于自己的工程并安装Genymotion模拟器
- LeetCode@Tree_617_Merge_Two_Binary_Trees
- github中配置SSHKEY
- Android图片查看(一)
- SQL四种语言:DDL,DML,DCL,TCL