我的计算列在我的视图中有问题。创建索引视图时出错
SELECT ColumnC, ColumnA % ColumnB AS ModuloColAColB, COUNT_BIG(*) AS cBig FROM dbo.T1
GROUP BY ColumnC, ModuloColAColB
查询与此类似MSDN例如: http://msdn.microsoft.com/en-us/library/ms191432.aspx
当我尝试编译视图我收到错误信息,如: “无效列名ModuloColAColB”
所以我用柱更改组名称:
SELECT ColumnC, ColumnA % ColumnB AS ModuloColAColB,
COUNT_BIG(*) AS cBig FROM dbo.T1
GROUP BY ColumnC, ColumnA, ColumnB
视图编译正确,但当我尝试添加索引我收到错误:
"Cannot create the clustered index 'px_test' on view 'l' because the select list of the view contains an expression on result of aggregate function or grouping column.
Consider removing expression on result of aggregate function or grouping column from select list"
当我删除“ColumnA%ColumnB AS ModuloColAColB”一切正常。
数据库版本:SQL Server 2005企业版。
在简单的重复,当你使用 GROUP BY ColumnC会发生什么,ColumnA%ColumnB – 2009-12-04 12:04:52
的观点是正确的编译,但不能创建索引 – itdebeloper 2009-12-07 21:42:13