TSQL Cannot create index on view - the view uses an implicit conversion from string to datetime -


sql server 2008 r2

i'm trying create indexed view i'm getting following error

cannot create index on view '' because view uses implicit conversion string datetime or smalldatetime. use explicit convert deterministic style value.

the issue int column [gpstime] records number of seconds '1970-01-01 00:00:00' , i'm trying convert/cast datetime, eg

cast(dateadd(ss,[gpstime],'1970-01-01' ) datetime) 

or

convert(varchar,dateadd(ss,[gpstime],'1970-01-01' ),113) 

or

convert(datetime,dateadd(ss,[gpstime],'1970-01-01' ),113) 

each of 3 options above gives me error mentioned earlier.

is way around this?

going make guess issue on '1970-01-01', try this:

dateadd(ss, gpstime, convert(datetime, '1970-01-01', 101)) 

or keep datetime value in table (as datetime avoid convert) or write deterministic function return datetime such:

create function [dbo].[unixepoch] () returns datetime schemabinding begin     return convert(datetime, '1970-01-01', 101) end  go  select objectproperty(object_id('[dbo].[unixepoch]'), 'isdeterministic')  select dbo.unixepoch() 

edit:

note datetime style applied convert(datetime, '1970-01-01', 101)

according documentation @ http://msdn.microsoft.com/en-us/library/ms178091.aspx :

source or target type datetime or smalldatetime, other source or target type character string, , nondeterministic style specified. deterministic, style parameter must constant. additionally, styles less or equal 100 nondeterministic, except styles 20 , 21. styles greater 100 deterministic, except styles 106, 107, 109 , 113.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -