zoukankan      html  css  js  c++  java
  • sql 游标、sql server 游标使用、实例

    if object_Id('tempdb..#Temp1010')is not null
        drop table #Temp1010
    go
    if object_Id('tempdb..#Temp2020')is not null
        drop table #Temp2020
    go
    create table #Temp2020(
            it_id nvarchar(100) null   
            );
    insert #Temp2020 (it_id)values(1)
    insert #Temp2020 (it_id)values(2)
    insert #Temp2020 (it_id)values(3)
    create table #Temp1010(
            it_id nvarchar(100) null,   
            pc_total nvarchar(100) null,
            note_total nvarchar(100) null
            );
    DECLARE
            @it_id nvarchar(100),
            @pc_total nvarchar(100),
            @note_total nvarchar(100);

    --声明游标

    DECLARE MainCursor CURSOR FOR select it_id from  #Temp2020

        --打开游标
        OPEN MainCursor

            --提取数据
            FETCH NEXT FROM MainCursor into @it_id 
            WHILE @@FETCH_STATUS = 0
                BEGIN
                    begin
                    set @pc_total = N'101'
                    set @note_total = N'102'
                    insert into #Temp1010 values(@it_id,@pc_total,@note_total)
                    end           
                FETCH NEXT FROM MainCursor INTO @it_id 
                END

        --关闭游标
        CLOSE MainCursor
    DEALLOCATE MainCursor

    select * from #Temp1010

  • 相关阅读:
    password
    bzoj 1458: 士兵占领
    国家集训队2011 happiness
    cogs 2051. 王者之剑
    uva 10779 Collectors Problem
    [Jxoi2012]奇怪的道路
    天神下凡
    藏宝图
    黑红树
    愤怒的小鸟
  • 原文地址:https://www.cnblogs.com/ok519/p/1580358.html
Copyright © 2011-2022 走看看