Sample Header Ad - 728x90

Why does sys.fn_xe_file_target_read_file require an explicit cast on datetime2 column?

15 votes
2 answers
855 views
According to the documentation the returned column timestamp_utc should be of type *datetime2(7)* But when I query like this
SELECT 
    *
FROM sys.fn_xe_file_target_read_file('system_health*.xel', null, null, null)
WHERE timestamp_utc > dateadd(hour, -1, GETUTCDATE())
It returns no rows. It returns the rows only when I add an explicit cast to *datetime2*
SELECT 
    *
FROM sys.fn_xe_file_target_read_file('system_health*.xel', null, null, null)
WHERE cast(timestamp_utc as datetime2(7)) > dateadd(hour, -1, GETUTCDATE())
Which matches the last example in the documentation (even though no attention is drawn to it) enter image description here Why is that?
Asked by Zikato (5724 rep)
Feb 7, 2023, 08:56 AM
Last activity: May 13, 2025, 06:42 AM