This is a newbie question on creating an indexed view. The following code (minus proprietary field information) is my attempt at creating the indexed view. My resource for the information is Books Online.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
USE MyDataBase
GO
CREATE VIEW dbo.vwMyView
WITH SCHEMABINDING
AS SELECT <my field list>
FROM dbo.MyTable
WHERE MyDateField >= '1/1/2000'
AND <my other conditions>
GO
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
SET ARITHABORT ON
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
CREATE UNIQUE CLUSTERED INDEX RowID
ON dbo.vwMyView (RowID)
CREATE INDEX MyField
ON dbo.vwMyView (MyField)
GO
The view creates successfully and then the code generates the following error...
Error on the Unique clustered index:
Server: Msg 1957, Level 16, State 1, Line 1
Index on view 'dbo.vwMyView' cannot be created because the view requires a conversion involving dates or variants.
The data type for the RowID field is...
rowid (int, Not Null)
Though it doesn't seem relevant, the data type for the field in the second index is...
MyField (varchar(5), Null)
Also, the data type for the date field in the WHERE clause is...
MyDateField (datetime, Null)
I tried chasing down a relationship (in the generic sense and not the database sense) between variant from the error message and varchar from the data definition in the second index statement, but I don't think that's what it is. I'm stumped. Do you have any ideas?
Thanks!
Ray <><
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
USE MyDataBase
GO
CREATE VIEW dbo.vwMyView
WITH SCHEMABINDING
AS SELECT <my field list>
FROM dbo.MyTable
WHERE MyDateField >= '1/1/2000'
AND <my other conditions>
GO
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
SET ARITHABORT ON
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
CREATE UNIQUE CLUSTERED INDEX RowID
ON dbo.vwMyView (RowID)
CREATE INDEX MyField
ON dbo.vwMyView (MyField)
GO
The view creates successfully and then the code generates the following error...
Error on the Unique clustered index:
Server: Msg 1957, Level 16, State 1, Line 1
Index on view 'dbo.vwMyView' cannot be created because the view requires a conversion involving dates or variants.
The data type for the RowID field is...
rowid (int, Not Null)
Though it doesn't seem relevant, the data type for the field in the second index is...
MyField (varchar(5), Null)
Also, the data type for the date field in the WHERE clause is...
MyDateField (datetime, Null)
I tried chasing down a relationship (in the generic sense and not the database sense) between variant from the error message and varchar from the data definition in the second index statement, but I don't think that's what it is. I'm stumped. Do you have any ideas?
Thanks!
Ray <><