I have a table that has a datetime and a time field where the datetime is actually just the date and the time field is the time. I need to combine these 2 fields to create a "created_time" computed field. I'd like to persist this computed field but I keep getting a "non-deterministic" error when I'm trying to combine them. Firstly, I'm not sure I understand why it's non-determinstic, but secondly, is there any fancy way to get around that and accomplish this?
--------------------------------------------------------
date (datetime) | time (varchar)
--------------------------------------------------------
2021-05-05 00:00:00 | 12:00
2021-05-13 00:00:00 | 18:01
I've tried using the following computations and neither work.
ALTER TABLE dbo.table ADD created_time AS ([date] + [time]) PERSISTED
ALTER TABLE dbo.table ADD created_time AS (DATEADD(millisecond, DATEDIFF(millisecond, 0, [time]), [date])) PERSISTED