I'm trying to use the WITH statement in my queries but the result is always an empty array. Does it mean that the driver actually prevent us from using CTE Query Definition, even if we're using SQL-Server 2005 or later? I get no errors, simply not开发者_如何学Gohing.
WITH CarsTemp AS
(
SELECT *, ROW_NUMBER() OVER (ORDER BY Model) AS Row
FROM Cars
)
SELECT *
FROM CarsTemp
WHERE Row BETWEEN 1 AND 10
However, if I use the common embed syntax, it works fine.
SELECT * FROM
(
SELECT *, ROW_NUMBER() OVER (ORDER BY Model) AS Row
FROM Cars
) AS CarsTemp
WHERE Row BETWEEN 1 AND 10
Could anyone help me here? Why is that so?
My query looks like this:
sqlsrv_query($this->mssql, $query, $sqlParams, array( "Scrollable" => SQLSRV_CURSOR_KEYSET )
According to WITH common_table_expression (Transact-SQL), ORDER BY can NOT be used in CTE_query_definition. Since the order cannot be guaranteed in CTE_query_definition by ORDER BY.
The following clauses cannot be used in the CTE_query_definition:
COMPUTE or COMPUTE BY
ORDER BY (except when a TOP clause is specified)
INTO
OPTION clause with query hints
FOR XML
FOR BROWSE
精彩评论