I Have made a summerized view which i need it to cross with another view, both views needs to be indexed by 2 fields (number one field is date) so that i could improve performance on response time. When i try to do it i get the following message:
-- CREATING VIEW FOR VENTAS POR DISTRIBUIDOR, DEPARTAMENTO
create view [dbo].[vw_ventas_dist_dep] as
SELECT CAST(t.fecha AS DATE)fecha
,d.NombreDistribuidor distribuidor
,u.Nombre departamento
,sum(tr.monto) monto
from HechosTransferencia tr inner join DimensionTiempo t on tr.DimensionTiempoId=t.DimensionTiempoId
inner join DimensionDistribuidor d on d.DimensionDistribuidorId=tr.DimensionDistribuidorId
inner join DimUbigeo u on u.DimDepartamentoId=tr.DimDepartamentoId and u.DimProvinciaId='' and u.DimDistritoId=''
WHERE (t.Fecha BETWEEN DATEADD(MONTH, DATEDIFF(MONTH, - 3, GETDATE()) - 3, 0) AND GETDATE())
-- and t.fecha between '2016-12-19' and '2016-12-20' and d.NombreDistribuidor='auren S.A.'
and tr.TipoDestino='PDV' and tr.TipoOperacion='Transferencia'
group by CAST(t.fecha AS DATE),d.NombreDistribuidor,u.Nombre ;
GO
CREATE UNIQUE CLUSTERED INDEX PK_fecha ON vw_ventas
(
fecha, -- date field
distribuidor -- string field
);
Msg 1939, Level 16, State 1, Line 1
Cannot create index on view 'vw_ventas' because the view is not schema bound.
I have tried placing WITH SCHEMABINDING but dont get a way to make the indexed view.