I have been using the following string in a reporting query which pulls data from a server via ODBC. It is no longer working as expected:
cast (((SYSDATETIME ( ) - a.[Create Date/Time]))as int) as Age
The resulting error is: The data types datetime2 and datetime are incompatible in the subtract operator.
Any help would be appreciated.
This is SQL Server syntax, why don't you ask in a Microsoft forum?
SYSDATETIME returns a datetime2 and you can't use plus/minus on that datatype, you need to use DATEDIFF instead:
DATEDIFF(day, a.[Create Date/Time], SYSDATETIME ( ))
I inherited the query from someone else and did not realize I should post elsewhere. Thanks you so much for your help, Dieter.