view contains a convert that is imprecise or non-deterministic?

4.8k views Asked by At

My query:

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])

Gives me this error even though my convert is using deterministic 121 type:

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

There are 1 answers

0
Swathi On

Create INDEXED VIEWS.

You need to use a Deterministic Style in your CONVERT clause. The default is non-deterministic

Try,CONVERT(DECIMAL(10,2)) OR CONVERT(DATETIME, '20131202', 103)