[英]CTE Invalid column name
我完全堅持這個。 我查看了其他問題,但找不到回答這個問題的問題(無論如何我都能理解)。 我的查詢中有以下 CTE,但 MaxUserID 在與“無效列名'MaxUserID'”錯誤一起使用的 3 個地方呈紅色波浪線。 它應該代表的列是一個 int,如果有幫助的話。 有什么建議嗎?
我正在使用 SQL 服務器 2008。
;with TotalCount(TotalCount,MaxUserID)
as
(
Select ISNULL(count(distinct uCPR.HeaderID), 0) as TotalCount, MaxUserID
from ClientFeedback.dbo.UnitCountCPR uCPR
where
uCPR.DHDate between @StartDate and @EndDateMod
and uCPR.TargetID in (@StatusID)
and uCPR.UserID = MaxUserID
and uCPR.DTStamp between @StartDate and @EndDateMod
and uCPR.ClientID in (@ClientID)
group by MaxUserID
)
刷新您的智能感知緩存,然后使用您的表別名來選擇列。 此外,計數永遠不會是 null,您的 IsNull 對您沒有任何好處。 你使用 in 而不是 equals 有什么原因嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.