"Invalid usage of the option NEXT in the FETCH statement."

"Invalid usage of the option NEXT in the FETCH statement."

我不是 SQL 大师,所以我希望这不是什么大问题。 :) 这是我的 SQL:

query = "SELECT id, email, firstName, lastName " +
        "FROM [WarehouseUser] " +
        "WHERE email LIKE '%' + @Filter + '%' OR FirstName LIKE '%' + @Filter + '%' OR LastName LIKE '%' + @Filter + '%'" +
        "ORDER BY " + "DESC" +
        "OFFSET @Offset ROWS " +
        "FETCH NEXT @Length ROWS ONLY;";

执行此操作时出现以下错误:

System.Data.SqlClient.SqlException: 'Incorrect syntax near '@Offset'. Invalid usage of the option NEXT in the FETCH statement.'

我做错了什么?

当您输出变量的值并查看它写入的 SQL 查询时,您可以看到问题。 "DESC" 之后需要一个 space。喜欢"DESC "。您目前有 DESCOFFSET 而不是 DESC OFFSET。在这里查看:

http://rextester.com/live/RKRXM8567