2009-12-04 6 views
1

뷰의 계산 열에 문제가 있습니다. 내가 같은 오류 메시지를 수신보기 컴파일 할 때 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, ModuloColAColB 

쿼리는이 MSDN 예제와 유사합니다 이름 :

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 Enterprise Edition.

+1

GROUP BY ColumnC, ColumnA % ColumnB –

+0

보기가 올바르게 컴파일되지만 나타낼 수 없습니다. 색인 – itdebeloper

답변

1

시도 GROUP BY ColumnC, ColumnA % ColumnB? 귀하의 링크에서

:

..cannot contain... An expression on a column used in the GROUP BY clause, or an expression on the results of an aggregate.

나는 이것이 당신이 열을 기준으로 그룹에 모듈로 할 수 없음을 의미 생각합니다. 그러나 GROUP BY에서 표현식을 수행하고 select 절에서 간단히 반복 할 수 있어야합니다.

+0

을 찾았습니다. ...이 msdn 페이지의 예제는 SQL 서버에서 작동하지 않습니다. / – itdebeloper

관련 문제