尝试使用群集索引创建视图,通过使用schemabinding创建视图,继续运行到砖墙中。我在查询中使用了所有2部分标识符,并且我已遵循Microsoft网站上的所有规则(https://docs.microsoft.com/en-us/sql/relational-databases/views/create-indexed-views)
由于某种原因,它只是不想启用架构绑定(我能够创建没有架构绑定的视图,但我希望有一个索引视图用于性能目的)
alter view dbo.v_rolling_12_sales with SCHEMABINDING
as
select c.ChainName, c.ChainID, s.SupplierName, s.SupplierIdentifier, s.SupplierID,
sum(isnull(i.TotalCost,0)) as costDollars, sum(isnull(i.TotalRetail,0)) as retailDollars, COUNT_BIG(*) as countBig
from DataTrue_Report.dbo.InvoiceDetails as i with (nolock)
inner join DataTrue_Report.dbo.Suppliers as s
on s.SupplierID = i.SupplierID
inner join DataTrue_Report.dbo.Chains as c
on c.ChainID = i.ChainID
where s.IsRegulated = 0 and i.SaleDate > '2/13/17' and i.InvoiceDetailTypeID in (1,7) and i.TotalQty > 0
group by c.ChainName, s.SupplierName, s.SupplierIdentifier, c.ChainName, c.ChainID, s.SupplierName, s.SupplierIdentifier, s.SupplierID
GO
CREATE UNIQUE CLUSTERED INDEX ChainSupplier ON v_rolling_12_sales (SupplierID, ChainID, ChainName, SupplierIdentifier, SupplierName)
GO
答案 0 :(得分:0)
物化视图中的聚合函数不应引用可归零的列。尝试使用非可空列的聚合函数。并且还包括count_big(*)以及您的聚合功能。
此致 Ananda Kumar J。