views:

72

answers:

1

Hi, I have the following query:

WITH cte AS (
    SELECT
        windowId, frameIndx, elemIndx, comment, 
        ROW_NUMBER() OVER (PARTITION BY frameIndx ORDER BY elemIndx DESC)
    AS
        rn
    FROM
        dbo.translations
    WHERE
        windowId = 1 AND frameIndx IN (
            SELECT
                indx
            FROM
                dbo.translations_window
            WHERE program_id = 1 AND active = 1
    )
)
SELECT
    windowId, frameIndx, elemIndx, comment
FROM
    cte
WHERE
    rn = 1

The query is executed without problems when running in SQL Server 2008 R2 Developer (no matter how), SQL Server 2005 Express and SQL Server 2008 R2 Express using the management studio (this work for the last two). But as soon as I try to execute this queries using ADODB from Delphi I get an error saying.

Incorrect syntax near the keyword WITH

Are these kind of queries disallowed in the express versions of SQL? what is the problem in the query? The client uses SQL express, so I need to find a solution with this problem which runs in the express version.

+7  A: 

I don't know if it helps, but you could try to put a semicolon before your query:

; WITH cte AS (
...
Peter Lang
So 4 upvotes and an accept.... Does Sambatyon confirm that this fixes the problem? If so, I'll upvote as well.
Chris Thornton
I can confirm that this is needed to use CTEs on ADODB queries.
Fabricio Araujo
Most documentation using CTEs I've seen suggests adding a ; before the with, basically "to be sure to be sure".
Gerry