Given the following fields:
Y INT, --Year.
M INT, --Month.
D INT, --Day.
T FLOAT --Hours (H), minutes (m), seconds (s) and milliseconds (x) (in the form HHmmss.xxx).
Is there a way to attempt to convert these values into a DATETIME2
without having to first convert them to a string-based data type? If the attempt fails (e.g. due to an overflowing day value (e.g. 35th of January 2019)), I would like NULL
to be returned.
If I use DATETIME2FROMPARTS
it will simply fail if passed any invalid component.
I am trying to avoid converting these into a string as the only reason I am trying this compromised solution is because the performance of my other solution which actually handles overflow and underflow, is incredibly slow against a large database (doesn't complete in 5 hours!) so I'm trying to try something simpler to see if it improves the performance of adding this as a computed persisted column.