I’m querying a varchar column that contains all valid datetimes. In the query, I cast the column to datetime.
Keep in mind, changing the column’s datatype definition to datetime is not an option. Just trust me, it’s not an option.
Through query analysis, I see that the query would be much faster if I could add an index on this column. But it’s varchar. If I added an index, it would index based on it’s varchar value, right? But I’d want it to index on the datetime value, yes?
Is there anything I can do here for an index?
Valid data is the first priority, because any approach that converts the data to DATETIME will return a value of January 1, 1900 at midnight when the value doesn’t match an accepted format.
SQL Server doesn’t have function based indexes, so your options are: