一次排序序号的补充
由于疏忽,数据库的排序字段,成了0,导致,排序出现错误
下面这个,单独执行,给再加上了排序
1 declare @testPagerId int 2 set @testPagerId=12 3 4 IF OBJECT_ID('dbo.#GroupQuestion','U') IS NOT NULL DROP TABLE dbo.#GroupQuestion; 5 6 SELECT * 7 INTO dbo.#GroupQuestion 8 FROM GroupQuestion where testPagerId=@testPagerId 9 order by id 10 11 -- 声明变量 12 DECLARE 13 @id INT, 14 @rank int 15 set @rank=0 16 17 WHILE EXISTS(SELECT id FROM dbo.#GroupQuestion) 18 BEGIN 19 -- 也可以使用top 1 20 set @rank=@rank+1 21 SELECT top 1 @id=id FROM dbo.#GroupQuestion; 22 UPDATE GroupQuestion SET sort=@rank WHERE id=@id; 23 DELETE FROM dbo.#GroupQuestion WHERE id=@id; 24 END 25 select * from dbo.#GroupQuestion 26 DROP TABLE dbo.#GroupQuestion;