CTE 列名无效
我完全被这个问题困住了。我查看了其他问题,但找不到回答这个问题的问题(无论如何,我可以理解)。我的查询中有以下 CTE,但 MaxUserID 在使用它的 3 个地方显示为红色波浪线,并出现“无效的列名‘MaxUserID’”错误。它应该代表的列是一个 int,如果有帮助的话。有什么建议吗?
我正在使用 SQL Server 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
)
I am completely stuck on this one. I looked in the other questions, but could not find one that answered this (that I could understand, anyway). I have the following CTE in my query but MaxUserID is squiggled red in the 3 places it's used with an "invalid column name 'MaxUserID'" error. The column it should represent is an int, if that helps. Any advice?
I'm using SQL Server 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
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刷新您的智能感知缓存,然后使用您的表别名来选择列。另外, count 永远不会为空,你的 IsNull 对你没有任何好处。您使用 in 而不是 equals 是否有原因?
Refresh your intellisense cache, and then use your table alias to pick the coluumns. Also, count will never be null, your IsNull isn't doing you any good. And is there a reason you are using in instead of equals?