Hi @Bobby P ,
Welcome to Microsoft Q&A!
You could not create an index based on a function in SQL Server. You can however create an index on a computed column (with restrictions, such as the computation has to use only deterministic functions).
In your example, you could firstly try with below:
ALTER TABLE dbo.[Enrollment]
ADD
CreateEastern AS
TRY_CONVERT (DATE, [Common].[dbo].[UTCtoEastern] ([Enrollment].[CreateUTC]),101),
UpdateEastern AS
TRY_CONVERT (DATE, [Common].[dbo].[UTCtoEastern] ([Enrollment].[UpdateUTC]),101);
CREATE INDEX ix_CreateEastern
ON dbo.[Enrollment](CreateEastern);
CREATE INDEX ix_UpdateEastern
ON dbo.[Enrollment](UpdateEastern);
If you face any error like 'Column 'CreateEastern' in table 'dbo.Enrollment' cannot be used in an index or statistics or as a partition key because it is non-deterministic.', you could refer Deterministic and Nondeterministic Functions and check whether your function is deterministic or not.
If your function is non-deterministic (e.g. when you call it with the same input parameters, there's no guarantee you'll get the same results every time), it cannot be indexed.
The only way around this would be to make it a regular column (not based on a function), and just update the value stored in that column on a regular basis.
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.