--排序列
SELECT displayrate,ROW_NUMBER() OVER (ORDER BY displayrate desc) AS rowid 
 from #ListH  
 
--临时表
 IF OBJECT_ID (‘tempdb..#tCategoryTable‘) IS NOT NULL
 BEGIN
    DROP TABLE #tCategoryTable;
 END;
 CREATE TABLE #tCategoryTable( CategoryID INT );
 
--游标
declare @id int
 
declare mycursor cursor for
select id  from  table1
open mycursor
fetch next from mycursor into @id
while @@FETCH_STATUS = 0
begin
       --sql handle
       fetch next from mycursor into @id
end
 
close mycursor
deallocate mycursor
 SQL 大全(3)
原文:http://www.cnblogs.com/stepheu/p/4347928.html