zoukankan      html  css  js  c++  java
  • MSSQLSERVER数据库- 上移和下移的存储过程

    做一下备忘

    MOVEUP:

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    
    
    
    
    
    ALTER PROCEDURE [dbo].[Proc_MoveUp] 
        @id int
    AS
    BEGIN
    
        declare @preSort int;--上一条记录的排序值
        declare @preid int; --上一条记录的id值
        declare @curSort int;--当前记录的排序值
    
        with TB As (select top 1000 *,row_number() over(order by Sort desc,id desc) as rowid from T_Move order by Sort desc,id desc)
        select @preSort=sort,@preid=id from TB where rowid=(select rowid+1 from TB where id=@id);
        select @curSort=Sort From T_Move Where id=@id;
    
        update T_Move set Sort=@preSort where id=@id;
        update T_Move set SOrt=@curSort where id=@preid
    
    
    END

    MOVEDOW:

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    
    
    
    
    
    ALTER PROCEDURE [dbo].[Proc_MoveDown] 
        @id int
    AS
    BEGIN
    
        declare @nextSort int;--上一条记录的排序值
        declare @nextid int; --上一条记录的id值
        declare @curSort int;--当前记录的排序值
    
        with TB As (select top 1000 *,row_number() over(order by Sort desc,id desc) as rowid from T_Move order by Sort desc,id desc)
        select @nextSort=sort,@nextid=id from TB where rowid=(select rowid-1 from TB where id=@id);
        select @curSort=Sort From T_Move Where id=@id;
    
        update T_Move set Sort=@nextSort where id=@id;
        update T_Move set SOrt=@curSort where id=@nextid
    
    END
  • 相关阅读:
    网络知识: 物理层PHY 和 网络层MAC
    Android lowmemorykiller
    devres in linux driver
    spinlock in linux kernel
    JavaWeb图片URL中文乱码
    Linux 里的 2>&1含义
    python脚本linux上后台执行
    linux之定时任务
    python中if not x: 和 if x is not None: 和 if not x is None的使用和区别
    私钥和公钥的区别和联系
  • 原文地址:https://www.cnblogs.com/cxeye/p/3591067.html
Copyright © 2011-2022 走看看