1

The following code failed when we had to switch to the SQL Server Native Client 11.0 driver (so that we could upgrade our TLS to 1.2):

convert(varchar(15),getdate()+cast(1 as datetime),10)

The error was:

Microsoft SQL Server Native Client 11.0 : The data types datetime2 and datetime are incompatible in the add operator.

We can change the T-SQL code to get around this (maybe with a DATEADD), but it is legacy code in 250 scripts in our system. Is there something we can do at the native client interface level or is there a global option we can set?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
fthurber
  • 11
  • 1
  • 1
    You should change the legacy code. Adding and subtracting dates from date/datetime/datetime2 should be done with `dateadd`. For more information, read Aaron Bertrand's [Bad Habits to Kick : Using shorthand with date/time operations](https://sqlblog.org/2011/09/20/bad-habits-to-kick-using-shorthand-with-date-time-operations) – Zohar Peled Apr 15 '18 at 15:15

0 Answers0