-- ╔════════╗
-- =============================== ║ 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
--

SqlServer中循环和条件语句示例!的更多相关文章

  1. SqlServer中循环和条件语句

    if语句使用示例 declare @a int              set @a=12              if @a>100                 begin      ...

  2. SQL中循环和条件语句

    .if语句使用示例: declare @a int begin print @a end else begin print 'no' end .while语句使用示例: declare @i int ...

  3. 【转载】 Sqlserver中通过Select Into语句快速单表备份

    在Sqlserver数据库中,备份数据的方式有很多种,可以使用整个数据库备份,也可使用导出包含数据和架构的脚本文件的方式来进行单表或多表数据的备份,其实还有一种Select Into的方式可以快速备份 ...

  4. Python中循环及判断语句

    循环判断条件是编程语言中一个很重要的部分,python也不例外,循环判断条件一般结合continue,return,break关键字来判断,这些关键字用法与java中基本一致 一.if判断语句 判断条 ...

  5. shell脚本中的case条件语句介绍和使用案例

    #前言:这篇我们接着写shell的另外一个条件语句case,上篇讲解了if条件语句.case条件语句我们常用于实现系统服务启动脚本等场景,case条件语句也相当于if条件语句多分支结构,多个选择,ca ...

  6. shell脚本中的if条件语句介绍和使用案例

    #前言:在生产工作中if条件语句是最常使用的,如使用来判断服务状态,监控服务器的CPU,内存,磁盘等操作,所以我们需要熟悉和掌握if条件语句. #简介 if条件语句,简单来说就是:如果,那么.有if单 ...

  7. sass中的循环判断条件语句

    @if $lte7:true !default;//是否兼容ie6,7 //inline-block //ie6-7 *display: inline;*zoom:1; @mixin inline-b ...

  8. 在SQLSERVER中快速有条件删除海量数据技巧推荐

    解释: 如果你的硬盘空间小,并且不想设置数据库的日志为最小(因为希望其他正常的日志希望仍然记录),而且对速度要求比较高,并清除所有的数据建议你用turncate table1,因为truncate 是 ...

  9. SqlServer中循环给多张表建立聚簇索引

    缘由 因为在某个复(bian)杂(tai)需求中用到了170+张表进行查询,而且表中的数据过多,查起来缓慢.只能给这些表添加索引.但是,连表名也是无法确定的(无力吐槽). 解决方法 使用游标遍历查询出 ...

随机推荐

  1. java一些面试题

    java虚拟机 什么时候会触发full gc System.gc()方法的调用 老年代空间不足 永生区空间不足(JVM规范中运行时数据区域中的方法区,在HotSpot虚拟机中又被习惯称为永生代或者永生 ...

  2. HDU 2491 Priest John's Busiest Day(贪心)(2008 Asia Regional Beijing)

    Description John is the only priest in his town. October 26th is the John's busiest day in a year be ...

  3. 为什么23种设计模式中没有MVC

    GoF (Gang of Four,四人组, <Design Patterns: Elements of Reusable Object-Oriented Software>/<设计 ...

  4. 20145214实验三 敏捷开发与XP实践

    20145214实验三 敏捷开发与XP实践 XP准则 沟通 :XP认为项目成员之间的沟通是项目成功的关键,并把沟通看作项目中间协调与合作的主要推动因素. 简单 :XP假定未来不能可靠地预测,在现在考虑 ...

  5. Spring Security 快速了解

    在Spring Security之前 我曾经使用 Interceptor 实现了一个简单网站Demo的登录拦截和Session处理工作,虽然能够实现相应的功能,但是无疑Spring Security提 ...

  6. MyBatis 基本构成与框架搭建

    核心组件 SqlSessionFactoryBuilder (构造器) 根据配置信息(eg:mybatis-config.xml)或者代码来生成SqlSessionFactory. SqlSessio ...

  7. Android框架 与 源码结构

    一. Android 框架 Android框架层级 : Android 自下 而 上 分为 4层; -- Linux内核层; -- 各种库 和 Android运行环境层; -- 应用框架层; -- 应 ...

  8. Ubuntu下FileZilla的安装

    FileZilla是一个免费而且开源的FTP客户端软件,共有两种版本:客户端版本.服务器版本.FileZilla有条理的界面和管理多站点的简化方式使得FileZilla Client成为一个方便高效的 ...

  9. java定时执行任务(一)

    需求: 经常遇到这样的需求:要求每天执行一次任务,执行任务时间是凌晨3点 实现: 为了便于检测,我假设的是下一分钟执行任务,每10秒重复执行.(对应现实项目:每天3点执行任务.那么就是下一个3点执行任 ...

  10. Ubuntu使用时遇到的问题

    启动时显示System program problem detected 解决办法: 打开命令行窗口:Ctrl+Alt+T 执行命令:sudo gedit /etc/default/apport 把e ...