• SQL server 不使用游标,使用临时表去获取数据,遍历处理数据


    SET QUOTED_IDENTIFIER ON
    SET ANSI_NULLS ON
    GO
    CREATE PROCEDURE [dbo].[SP_ConfirmScaner]
    AS
        BEGIN
            --SET STATISTICS IO ON
         
     
            DECLARE @ScanerTime DATETIME ,
                @InProvinceTimeDiffMinute INT ,
                @InProvinceStockTimeDiffMinute INT ,
                @UpdateState VARCHAR(20);
    
            SET @ScanerTime = GETDATE();
           -- SET @ScanerTime = '2019-10-01';
     
            SET @InProvinceTimeDiffMinute = 36 * 60 + 48 * 60;
     
            SET @InProvinceStockTimeDiffMinute = 72 * 60 + 48 * 60;
            SET @UpdateState = '000';
    
    
    
    
     
            DECLARE @DistanceTable TABLE ( id INT IDENTITY(1, 1) ,
                                           SendFlag BIT ,
                                           DiffMinute INT ,
                                           MinDistance INT ,
                                           MaxDistance INT );
            INSERT  INTO @DistanceTable ( SendFlag, DiffMinute, MinDistance,
                                          MaxDistance )
                    SELECT  0, 48 * 60 + 48 * 60, -99999, 499
                    UNION
                    SELECT  0, 72 * 60 + 48 * 60, 500, 999
                    UNION
                    SELECT  0, 96 * 60 + 48 * 60, 1000, 1999
                    UNION
                    SELECT  0, 168 * 60 + 48 * 60, 2000, 99999
                    UNION
                    SELECT  1, 96 * 60 + 48 * 60, -99999, 499
                    UNION
                    SELECT  1, 120 * 60 + 48 * 60, 500, 999
                    UNION
                    SELECT  1, 144 * 60 + 48 * 60, 1000, 1999
                    UNION
                    SELECT  1, 216 * 60 + 48 * 60, 2000, 99999;
    
            DECLARE @count INT;
            DECLARE @CurrentId INT;
            DECLARE @DiffMinute INT ,
                @MinDistance INT ,
                @MaxDistance INT ,
                @SendFlag bit;
            SELECT  @count = COUNT(0)
            FROM    @DistanceTable
            WHILE ( @count > 0 )
                BEGIN
                    SELECT TOP 1
                            @CurrentId = id, @SendFlag = SendFlag,
                            @DiffMinute = DiffMinute, @MinDistance = MinDistance,
                            @MaxDistance = MaxDistance
                    FROM    @DistanceTable AS a; 
    
    
                    DELETE  FROM @DistanceTable
                    WHERE   id = @CurrentId 
                    SELECT  @count = COUNT(0)
                    FROM    @DistanceTable
                END
            RETURN;
        END
    
    
    GO

    SQL server 不使用游标,使用临时表去获取数据,遍历处理数据

  • 相关阅读:
    Redis 客户端
    Redis 数据库
    Redis 对象
    Redis 跳跃表
    Redis 字典
    Redis 链表实现
    Redis 事务
    winform,自定义文本框控件 实现文本框验证加水印功能
    WinForm中,每隔一段时间(参数)调用一次函数(使用定时器)
    GMap.Net 实现离线地图
  • 原文地址:https://www.cnblogs.com/niceletter/p/11975648.html
Copyright © 2020-2023  润新知