首页 > 代码库 > 排序更改

排序更改

 

 1 select p.Id,p.Title,g.* from testPager p 2 inner join pageQuestionGroup g on p.id=g.testPagerId 3 where publicDate is null 4 order by p.id,g.id 5  6   7  8  9 declare @testPagerId int10 set @testPagerId=3311 12 IF OBJECT_ID(dbo.#GroupQuestion,U) IS NOT NULL DROP TABLE dbo.#GroupQuestion;13 14 SELECT *15 INTO dbo.#GroupQuestion16 FROM GroupQuestion where testPagerId=@testPagerId17 order by id18 19 -- 声明变量20 DECLARE21 @id INT,22 @rank int23 set @rank=024 25 WHILE EXISTS(SELECT id FROM dbo.#GroupQuestion)26 BEGIN27 -- 也可以使用top 128 set @rank=@rank+129 SELECT top 1 @id=id FROM dbo.#GroupQuestion;30 UPDATE GroupQuestion SET sort=@rank WHERE id=@id; 31 DELETE FROM dbo.#GroupQuestion WHERE id=@id;32 END33 select * from dbo.#GroupQuestion34 DROP TABLE dbo.#GroupQuestion;

 

排序更改