无法创建索引视图

时间:2018-12-04 03:38:06

标签: sql-server tsql indexing indexed-view

我在论坛上读过,索引视图可以存储表,因此可以提高性能。如何修改下面的查询以将NewDate用作唯一索引?我也知道索引查询有一些限制。有人可以在这里引导我吗?

CREATE VIEW [dbo].[DenisGroup] AS
SELECT NewDate,
TStamp,EnergyAC3,Irradiation,EnergyAC2,StationID,EnergyAC,
FROM
(
ROW_NUMBER() OVER (PARTITION BY CAST(Date1 AS date) ORDER BY TStamp DESC) AS Seq,TRY_CAST(Date1 as date) AS NewDate, Tstamp, 
case when ([Eac1] >6000 OR [Eac1] = NULL OR [Eac1]=0)
    THEN '5000'
    ELSE [Eac1]
       end AS EnergyAC3,
       (([DailySpecYield1]*100)/[PR1]) AS Irradiation, [LastTime] , 0 AS EnergyAC2,REPLACE(StnId, 'MY-001X','MY-001') as StationID,0 AS EnergyAC
FROM [dbo].[MY-001X-4G]
UNION ALL
ROW_NUMBER() OVER (PARTITION BY CAST(Date1 AS date) ORDER BY TStamp DESC) AS Seq,TRY_CAST(Date1 as date) AS NewDate, Tstamp, 
case when ([MFM1.Eac2] >6000 OR [MFM1.Eac2] = NULL OR [MFM1.Eac2]=0)
    THEN '5000'
    ELSE [MFM1.Eac2]
       end AS EnergyAC,
       case when ([WMS.GTI] IS NULL)
       then '4.52'
       when ([WMS.GTI] < 0) then '3'
       when ([WMS.GTI]> 7) then '3.95'
       else [WMS.GTI] end AS Irradiation, [MFM1.LastTime] , [MFM2-Eac1] AS EnergyAC2,0 AS EnergyAC3,REPLACE(StnId, 'MY-002C','MY-002') as StationID
FROM [dbo].[MY-002C-4G]
)t
WHERE Seq = 1
GO

0 个答案:

没有答案