gpt4 book ai didi

sql - 消息 208,级别 16,状态 1,第 1 行对象名称无效

转载 作者:行者123 更新时间:2023-12-05 06:44:38 27 4
gpt4 key购买 nike

我正在尝试从使用 WITH 创建的 SalesData 中进行选择,查询是

    with SalesData (TotalSold, OrderYear, TerritoryName)
AS (

SELECT SUM(soh.TotalDue) AS 'TotalSold'
, YEAR(soh.OrderDate) AS 'OrderYear'
, st.Name AS 'TerritoryName'
FROM Sales.SalesOrderHeader AS soh
INNER JOIN Sales.SalesTerritory AS st
ON soh.TerritoryID = st.TerritoryID
GROUP BY YEAR(soh.OrderDate)
,st.Name
)
SELECT TotalSold FROM SalesData

但是 SSMS 给我这个错误:

Msg 208, Level 16, State 1, Line 1 Invalid object name

我正在使用 Avdentureworks 数据库示例。

enter image description here

知道为什么会这样吗?虽然它在演示视频中执行得很好我正在看。

最佳答案

基于 @DeepakPawar 的评论解决方案是

put a semicolon before with like

;with cte (...) as ....

也为 @Pரதீப்提及-引用以下WITH common_table_expression (Transact-SQL) documentation

When a CTE is used in a statement that is part of a batch, the statement before it must be followed by a semicolon

关于sql - 消息 208,级别 16,状态 1,第 1 行对象名称无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28294832/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com