view包含一个不精确或不确定的转换?

时间:2013-12-02 02:34:08

标签: sql sql-server indexing type-conversion clustered-index

我的查询:

IF OBJECT_ID ('vw_F_GWLVL_RAW', 'V') IS NOT NULL
DROP VIEW vw_F_GWLVL_RAW ;
GO

CREATE VIEW vw_F_GWLVL_RAW WITH SCHEMABINDING
AS
SELECT  S.SiteName,  CAST(D.[Date] as Date) as [Date], CONVERT(CHAR(5),T.[Time]) as [Time], CAST(F.SampleValue as NUMERIC(6,3)) as ValueAsRecorded,
            Q.Code as DataQualityCode, Q.QualityDesc as DataQualityDesc

FROM        dbo.F_GWLVL_RAW AS F INNER JOIN
                      dbo.D_Site AS S ON F.D_Site_Key = S.D_Site_Key INNER JOIN
                      dbo.D_Date AS D ON F.D_Date_Key = D.D_Date_Key INNER JOIN
                      dbo.D_Time AS T ON F.D_Time_Key = T.D_Time_Key INNER JOIN
                      dbo.F_ODP_QC_GWLVL AS Q ON Q.[Site] collate database_default = S.[SiteName] AND
                      (CONVERT(datetime,CAST(D.[Date] as VARCHAR(30))+' '+CAST(T.[Time] as VARCHAR(30)),121) BETWEEN Q.StartTime AND Q.EndTime)


GO
CREATE UNIQUE CLUSTERED INDEX IX_GWLVL_RAW1 ON vw_F_GWLVL_RAW(SiteName,[Date],[Time])

即使我的转换使用确定性121类型,也会给我这个错误:

'Cannot create index on view "dbo.vw_F_GWLVL_RAW". The view contains a convert that is imprecise or non-deterministic.'

1 个答案:

答案 0 :(得分:0)

创建INDEXED VIEWS。

您需要在CONVERT子句中使用确定性样式。默认值是非确定性的

尝试,CONVERT(DECIMAL(10,2))或CONVERT(DATETIME,'20131202',103)