SQL Server WITH 不工作,语法无效?

发布于 2024-10-17 12:43:04 字数 375 浏览 2 评论 0原文

使用以下查询,

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

我得到以下返回:

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

对我来说看起来不错。我问了一个关于子查询的类似问题,但同样的逻辑在这里并不适用,因为我已经用名称 cteTest 给表起了别名。缺少什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不一样的天空 2024-10-24 12:43:04

尝试在“WITH”前面加一个分号。

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

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;
叫思念不要吵 2024-10-24 12:43:04

看起来这个特定的数据库位于不支持 CTE 的 SQL Server 8.0 上。看起来我必须解决子查询问题。

数字,在一家拥有 3 个不同版本的 SQL Server 的公司工作,我可能会忽略这一点。其他服务器是 9.0 并且支持这个功能很好,我从来没有必要针对这个特定的数据库编写带有 CTE 的东西,每天都学习新的东西:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文