读书人

简单分页的小疑点麻烦大家了~

发布时间: 2012-04-16 16:20:04 作者: rapoo

简单分页的小问题,麻烦大家了~~
我写了一个
select top 5 * from City where CityId not in (select top 5 CityId from City order by CityId)
这个正确
select top 5 * from City where CityId not in (select top 5*2 CityId from City order by CityId)
就报错:
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: '2 ' 附近有语法错误。

请问怎么解决啊?

[解决办法]
top 後面能接一具的字,如果要用量或者公式的可以用SQL句

declare @s varchar(8000)
set @s = 'select top 5 * from City where CityId not in (select top ' + ltrim(5*2) + ' CityId from City order by CityId) '

exec(@s)

读书人网 >SQL Server

热点推荐