2011-06-30 47 views
0

我完全陷在这一个。我查看了其他问题,但无法找到答案的人(无论如何我都能理解)。我的查询中有以下CTE,但MaxUserID在3个与“无效列名”MaxUserID'“错误一起使用的位置变成了红色。它应该表示的列是一个int,如果有帮助的话。有什么建议?CTE无效列名

我使用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 

) 
+2

在表UnitCountCPR中是否存在列MaxUserID? –

+0

您是否尝试过运行它?有时,intellisense(使红色下划线)与db结构不同步。您可以使用'CTRL + SHIFT + R'手动刷新它。 – JNK

+0

MaxUserID在表中不存在。 我曾尝试运行它,给我的错误。尽管我没有刷新智能感知。 – lonehunter01

回答

1

刷新你的智能感知缓存中,然后用你的表的别名挑coluumns。而且,count不会为空,你的IsNull对你没有任何好处。是否有一个原因,而不是平等使用?

+0

明天我会试试,但考虑到我在14小时,这听起来很合理。我需要输入,因为它来自SSRS报告,作为多选参数。我会摆脱isnull,谢谢你的帮助。 – lonehunter01