You will need to add a computed column
Alter Table BEER_HERE Add Column XBEER_DATE As dbo.TRUNCATE_DATE(BEER_DATE)
You can then index it, as you would expect.
However, your function must be deterministic and accurate, as defined in http://msdn.microsoft.com/en-us/library/ms189292(v=sql.90).aspx . Your function must meet these requirements, but you may need to add a function definition using SchemaBinding.
You can also use the view.
Create View V_BEER_HERE As Select BEER_CODE, BEER_DATE, dbo.TRUNCATE_DATE(BEER_DATE) As XBEER_DATE From BEER_HERE Create Unique Clustered Index PK_V_BEER_HERE On V_BEER_HERE (BEER_CODE) Create Index I_XBEER_DATE On V_BEER_HERE (XBEER_DATE)
Material that inserts records into a table, material that reads readings from a view. It depends on BEER_CODE being the primary key.
SQL Server does not have function-based indexes, just like Oracle does.
source share