SQL SERVER 2008 r2
I'm trying to Create an Indexed view however I'm getting the following error
Cannot create index on view '' because the view uses an implicit conversion from string to datetime or smalldatetime. Use an explicit CONVERT with a deterministic style value.
The issue is with an INT column [GPSTime] that records the number of seconds from '1970-01-01 00:00:00' and I'm trying to CONVERT/CAST this is to a DATETIME, eg
CAST(DATEADD(SS,[GPSTime],'1970-01-01' ) AS DATETIME)
or
CONVERT(VARCHAR,DATEADD(SS,[GPSTime],'1970-01-01' ),113)
or
CONVERT(DATETIME,DATEADD(SS,[GPSTime],'1970-01-01' ),113)
Each of the three options above gives me the error I mentioned earlier.
Is the way around this?
Going to make a guess that the issue is actually on the
'1970-01-01'
, try this:Or you could keep the datetime value in another table (as a datetime to avoid convert) or write a deterministic function to return your datetime as such:
EDIT:
note the datetime style applied to the
convert(datetime, '1970-01-01', 101)
according to documentation at http://msdn.microsoft.com/en-us/library/ms178091.aspx :