I use SQL Server 2008 R2
and know that in Indexed View
cant have self join.
I have a tree table that have ID
and ParentID
Column and I need create indexed view on this table with self join between each record and parent record. can I simulate self join in this view?
EDIT
My table structure is :
SAM.Detail (DetailID Int, ParentDetailID Int, Quantity Int, ...)
and my query is :
Select A.DetailID,
A.Quantity - SUM(B.Quantity) as RemainQuantity,
COUNT_BIG(*) as CountBig
From SAM.Detail A
inner join SAM.Detail B ON B.ParentDetailID = A.DetailID
Group By A.DetailID, A.Quantity
MIN/MAX
andPIVOT
are not allowed in indexed views so the pivoted view can't itself be indexed. Probably not worth doing. – Martin Smith Sep 3 '12 at 8:01