USEFUL SITES :
Write for Us
Error Message:Msg 10138, Level 16, State 1, Line 2Cannot create %S_MSG on view '%.*ls' because its select list does not include a proper use of COUNT_BIG. Consider adding COUNT_BIG(*) to select list.
Severity level:16.
Description:This error message appears when you try to use an aggregate function in an indexed view, without using the COUNT_BIG(*).
Consequences:The SQL statement cannot be parsed and further execution is stopped.
Resolution:Errors of the Severity Level 16 are generated by the user and are corrigible by the user. The statement cannot be executed this way. Indexed views using an aggregate functions must also use the COUNT_BIG(*) function.
Versions:This error message was introduced with SQL Server 2000.
Example(s):USE Northwind;GO
SET NUMERIC_ROUNDABORT OFF;SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, QUOTED_IDENTIFIER, ANSI_NULLS ON;GO
IF OBJECT_ID ('dbo.MyOrderView', 'View') > 0 DROP VIEW dbo.MyOrderView;GOCREATE VIEW dbo.MyOrderViewWITH SCHEMABINDINGASSELECT SUM(UnitPrice*Quantity*(1.00-Discount)) AS Revenue, OrderDate, ProductID FROM dbo.[Order Details] AS od JOIN dbo.Orders AS o ON od.OrderID = o.OrderID GROUP BY OrderDate, ProductID;GO
CREATE UNIQUE CLUSTERED INDEX cix_MyOrderView ON dbo.MyOrderView (OrderDate, ProductID);GO
Remarks:In the above example we try to use SUM() aggregate function in an indexed view. Because we don't also use the COUNT_BIG(*) function, the error is raised.