日期:2014-05-18 浏览次数:20500 次
CREATE TABLE t1(id INT IDENTITY(1,1),SortValue INT) INSERT INTO T1(SortValue) SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 20
declare @id int = 4 declare @change int = 2 -- 4,7 declare @group int = (select id-SortValue from T1 where SortValue=@change) update T1 set SortValue = case id when @id then @change else SortValue+1 end where id=@id or id-SortValue=@group and SortValue>=@change select * from T1