SQL Server WITH 不工作,语法无效?
使用以下查询,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在“WITH”前面加一个分号。
Try putting a semicolon in front of the "WITH".
看起来这个特定的数据库位于不支持 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 :)