zoukankan      html  css  js  c++  java
  • 【Vegas原创】SQL Server游标的经典使用

    昨天查关于游标的东西,发现我博客竟然没有~

    整理了一下,记录于此,以便以后查询使用。

    USE [PACSMonitor]
    GO
    /****** Object:  StoredProcedure [dbo].[sp_GetPSExamCountByDay]    Script Date: 04/22/2010 14:35:14 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[sp_GetPSExamCountByDay]
    AS
    DECLARE @date nvarchar(50)
     
    --先干其他的事情
    insert into dbo.rpt_psExamCountByDay(rptDate)
    select distinct substring((ex_cdt),1,8) from v_psExam 
    where substring((ex_cdt),1,8) COLLATE SQL_Latin1_General_CP1_CI_AS not in(select distinct rptdate from rpt_psExamCountByDay)
     
    --声明游标变量,取得数据--
    DECLARE contact_cursor CURSOR FOR
    SELECT rptDate FROM rpt_psExamCountByDay  
     
     
    --打开游标
    OPEN contact_cursor 
     
     
    FETCH NEXT FROM contact_cursor into @date  --开始抓第一条数据
    WHILE(@@fetch_status=0) 
        BEGIN     
            update rpt_psExamCountByDay
            set rptCount=(
                select COUNT(1) from v_psExam 
                where substring((ex_cdt),1,8) collate SQL_Latin1_General_CP1_CI_AS=@date)
                where rptDate=@date
                
            FETCH NEXT FROM contact_cursor into @date     --跳到下一条数据    
        END
     
     
    --关闭游标
    CLOSE contact_cursor
    --删除游标
    DEALLOCATE contact_cursor
     
     

    参考文档:http://msdn.microsoft.com/zh-cn/library/ms180152.aspx

    喜欢请赞赏一下啦^_^
  • 相关阅读:
    github fork项目后,代码更新
    UIScrollView的用法,属性
    调整屏幕亮度,调整字体大小
    iOS UIFont 字体名字大全
    ios 6以后,UILabel全属性
    oc中的各种遍历(迭代)方法
    判断app是否是第一次启动
    ios 显示代码块(show the code snippet library)
    ios 添加动画的方法
    添加app第一次启动页面
  • 原文地址:https://www.cnblogs.com/amadeuslee/p/3744167.html
Copyright © 2011-2022 走看看