首页 > 数据库技术 > 详细

MSSQLSERVER数据库- 上移和下移的存储过程

时间:2014-03-11 07:51:52      阅读:555      评论:0      收藏:0      [点我收藏+]

做一下备忘

MOVEUP:

bubuko.com,布布扣
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
bubuko.com,布布扣

MOVEDOW:

bubuko.com,布布扣
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
bubuko.com,布布扣

MSSQLSERVER数据库- 上移和下移的存储过程,布布扣,bubuko.com

MSSQLSERVER数据库- 上移和下移的存储过程

原文:http://www.cnblogs.com/cxeye/p/3591067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!