重置排序

create proc sp_ResetIndex
as
declare @c1 int
declare @c2 varchar(500)
declare @c3 int
declare my_curcor cursor
for( select ID,menuName,
(select COUNT(*) from tb_menu where menuSort<a.menuSort or (menuSort=a.menuSort and ID<a.ID))
from tb_menu a )
open my_curcor
fetch next from my_curcor into @c1,@c2,@c3
while (@@fetch_status=0)
begin
update tb_menu set menuSort=@c3 where ID=@c1
fetch next from my_curcor into @c1,@c2,@c3
end
close my_curcor
deallocate my_curcor

posted @ 2017-08-21 13:04  王宝会  阅读(212)  评论(0编辑  收藏  举报