ROW_NUMBER Alternative for SQL Server 2000

。_饼干妹妹 提交于 2019-12-20 05:31:47

问题


RIGHT now I'm using ROW_NUMBER() in my procedure in SQL Server 2008 as follows:

WITH cars as(SELECT carid,mileage,retailprice,imageurl,model,year, 
             Zips.Distance AS Miles, Manufacturers.mfgName as Make,
             dealers.companyname as companyname, CASE @sortby 
WHEN 'D' THEN ROW_NUMBER() OVER (ORDER BY  Manufacturers.mfgName) 
WHEN 'P' THEN ROW_NUMBER() OVER (ORDER BY retailprice) 
WHEN 'M' THEN ROW_NUMBER() OVER (ORDER BY mileage) 
END as 'rownum'
FROM usedcars INNER JOIN #TempZips Zips ON Zips.ZipCode =usedcars.loczip
left join Manufacturers on Manufacturers.mfgid=usedcars.mfgid 
left join dealers on dealers.dealerid = usedcars.dealerid 
where usedcars.active=1 and usedcars.dealerid=@dealerid)
select @totalrecords as totalrec,*  from cars 
where rownum between @skip and  @take

Is there an equivalent to this that works in SQL2000? (ROW_NUMBER wasn't introduced until SQL2005).


回答1:


You can create a temp table with an identity column, and insert your data into that.

Then use the temp table.



来源:https://stackoverflow.com/questions/3064788/row-number-alternative-for-sql-server-2000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!