Reputation: 6085
I have this razor statement
sql = "SELECT * FROM CarBike" +
"Order By id OFFSET @0 ROWS FETCH NEXT @1 ROWS ;";
var result = db.Query(sql, offset, pageSize);
i am getting error
Incorrect syntax near the keyword 'By'.
Invalid usage of the option NEXT in the FETCH statement.
System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'By'.
Invalid usage of the option NEXT in the FETCH statement.
Please help me to correct this error
Upvotes: 1
Views: 1299
Reputation: 51504
You need a space between CarBike
and Order by
sql = "SELECT * FROM CarBike" +
" Order By id OFFSET @0 ROWS FETCH NEXT @1 ROWS ;";
NB: OFFSET/FETCH
is SQL 2012+ only.
To achieve similar results in previous versions
select * from
(
select *, ROW_NUMBER() over (order by id) rn
from CarBike
) v
where rn between @0+1 and @0+@1
order by id
Upvotes: 3