with cte as
(
select rowid from batchinfo where datapath like '%thc%'
)
select * from qvalues where rowid in cte
我遇到了这个错误:
Msg 102, Level 15, State 1, Line 6 Incorrect syntax near 'cte'.
有人知道我做错了什么吗?
注:该错误信息提示语句中的“cte”附近存在语法错误。
with cte as
(
select rowid from batchinfo where datapath like '%thc%'
)
select * from qvalues where rowid in cte
我遇到了这个错误:
Msg 102, Level 15, State 1, Line 6 Incorrect syntax near 'cte'.
有人知道我做错了什么吗?
您将公共表表达式(CTE)视为子查询,而实际上应该更像表格使用。
尝试这个:
;with cte as
(
select rowid from batchinfo where datapath like '%thc%'
)
select * from qvalues
INNER JOIN cte on cte.rowid=qvalues.rowid
正如Al W的回答(以及Tony的评论)中随意提到的那样。错误被描述为发生在第6行,这意味着它不是批处理中的第一条语句。这意味着您需要在WITH关键字之前加上分号:
当CTE用于批处理的一部分语句中时,必须在其前面的语句后跟一个分号。
此外,从Transact-SQL Syntax conventions中可以看出:
尽管在此版本的SQL Server中大多数语句不需要分号,但在将来的版本中将需要。
因此,值得养成放置分号的习惯。