开发者

Microsoft Drivers for PHP for SQL Server don't seem to support CTE Query Definition

开发者 https://www.devze.com 2023-02-28 04:04 出处:网络
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-

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

0

精彩评论

暂无评论...
验证码 换一张
取 消