zoukankan      html  css  js  c++  java
  • SqlServer 游标

    DECLARE @PointID nvarchar(100),@RowID1 nvarchar(100)
     
    --声明一个游标( 可以把游标想象成每一条记录 )用来遍历查询到的结果
    DECLARE
        C_paraId CURSOR FOR 
          SELECT 
              a.PointID 
            FROM Report_Data a
            LEFT JOIN Report_Row b ON a.RowID = b.RowID
            LEFT JOIN Report_Day c ON b.ReportID = c.ReportID
            LEFT JOIN Report_Point d ON a.PointID = d.PointID
            LEFT JOIN Report_Monitor e ON d.MonitorID = e.MonitorID
            WHERE (1=1) AND (2=2)   and e.MonitorType=6 and c.MonitorId='5139cb6b-e34a-4d92-a2f8-1924f1ff7760'    and  a.PointID=418
            order by e.MonitorOrder,d.PointOrder,b.RowHour 
    
    --打开游标
    OPEN C_paraId 
    --获取游标指向的数据
    FETCH NEXT
    FROM  C_paraId INTO @PointID
    --使用游标遍历集合( @@FETCH_STATUS是默认全局变量,不用声明, =0表示匹配到了记录 )
    WHILE
        @@FETCH_STATUS = 0 
            BEGIN
       update [DB_PEMS].[dbo].[Report_Data]  set PointID='454'where PointID=@PointID   
         --游标指向下一条数据
         FETCH NEXT
         FROM C_paraId INTO @PointID
    END 
    --关闭游标
    CLOSE C_paraId 
    --释放游标
    DEALLOCATE C_paraId
    

      

  • 相关阅读:
    java的概述 常量 变量
    css 基础2
    css 盒子模型1
    css 基础1
    HTML 基础 3
    HTML基础2
    servletContext百科
    hibernate 一对多双向关联 详解
    hibernate generator class="" id详解
    Hibernate缓存原理与策略
  • 原文地址:https://www.cnblogs.com/wmyll/p/15073531.html
Copyright © 2011-2022 走看看