SQL Server 2000 的 ROW_NUMBER 替代方案 [英] ROW_NUMBER Alternative for SQL Server 2000
本文介绍了SQL Server 2000 的 ROW_NUMBER 替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我在 SQL Server 2008 的过程中使用 ROW_NUMBER() 如下:
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
在 SQL2000 中是否有与此等效的方法?(直到 SQL2005 才引入 ROW_NUMBER).
Is there an equivalent to this that works in SQL2000? (ROW_NUMBER wasn't introduced until SQL2005).
推荐答案
您可以创建一个带有标识列的临时表,并将您的数据插入其中.
You can create a temp table with an identity column, and insert your data into that.
然后使用临时表.
这篇关于SQL Server 2000 的 ROW_NUMBER 替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文