1

Using the following query,

WITH 
    cteTest (Employee_ID)
    AS
    (
        SELECT employee_ID FROM pep.dbo.labor_ticket
    )
SELECT Employee_ID FROM cteTest;

I get the following return:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'WITH'.

Looks right to me. I asked a similar question about a subquery but the same logic does not apply here as I have aliased the table with the name cteTest. What's missing?

2
  • This works for me, so you probably have a problem with code surrounding it.
    – LukLed
    Commented Feb 14, 2011 at 22:28
  • Nothing surrounding it whatsoever. I even highlight and execute, same deal... no CTE's will evaluate for me. Exit/Re-Open MGMT studio, same thing happens...
    – Mohgeroth
    Commented Feb 14, 2011 at 22:29

2 Answers 2

3

Try putting a semicolon in front of the "WITH".

;WITH 
    cteTest (Employee_ID)
    AS
    (
        SELECT employee_ID FROM pep.dbo.labor_ticket
    )
SELECT Employee_ID FROM cteTest;
1
  • 2
    Its not about starting the query with a semi-colon; its about ending the previous query with a semi-colon. Commented Feb 15, 2011 at 3:45
1

Looks like this particular database is on SQL Server 8.0 which does not support CTE. Looks like I'll have to settle with subqueries.

Figures, working for a company with 3 different versions of SQL Server that I would have overlooked this. The other servers are 9.0 and support this functionality just fine and I've never had to write something with a CTE against this particular DB, learn something new every day :)

1
  • Yes, CTE means SQL Server 2005.
    – LukLed
    Commented Feb 14, 2011 at 22:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.