-2
取我使用下面的示例代碼與SQL Server,它返回一個語法錯誤:SQL Server和語法錯誤
select id, user_id, cmd_id
from configs
order by user_id
offset 0 rows
fetch next 10 row only
如何調整語法?
取我使用下面的示例代碼與SQL Server,它返回一個語法錯誤:SQL Server和語法錯誤
select id, user_id, cmd_id
from configs
order by user_id
offset 0 rows
fetch next 10 row only
如何調整語法?
語法無誤。你在使用SQL 2012+嗎? Offset/Fetch子句在舊版本中不可用。
如果您使用的是舊版本,請嘗試以下操作:
with cte as
(
select id, user_id, cmd_id,
row_number() over (order by user_id) as rn
from configs
)
select id, user_id, cmd_id
from cte
where rn > 0 -- 0 is the offset
and rn <= 10 + 0 -- 10 is the limit + 0 the offset
我正在使用2008. Ty! – user4064663 2014-09-22 00:49:21
您正在使用什麼版本的SQL Server? – 2014-09-22 00:31:16
Mat,im using 2008. – user4064663 2014-09-22 00:48:49
閱讀文檔可能會很快回答這個問題。 – siride 2014-09-22 00:52:47