2

I am getting Arithmetic overflow error while executing following query on sql server 2016.

select cast(2958463.99999999 as datetime)

The same query works fine on sql server 2014.

enter image description here

Edit 1- select cast(2958463.9999999 as datetime) works on sql server, the only difference is that it used 7 digits after decimal point instead of 8 as originally posted.

John K. N.
  • 159
  • 16
mohit uprim
  • 5,226
  • 2
  • 24
  • 28
  • This error is caused by a change in Microsoft SQL Server 2016's handling of datetime types. – Yogesh Sharma Oct 25 '17 at 12:16
  • You sure there isn't anything more in the value? I just run it on couple versions and everywhere works in the same fashion. –  Oct 25 '17 at 12:16
  • 1
    @YogeshSharma could you elaborate? I'm curious. –  Oct 25 '17 at 12:17
  • The query works fine on mine 2016 instance. The output I get is `9999-12-31 23:59:59.997`. – Giorgos Betsos Oct 25 '17 at 12:18
  • even 'select cast(2958463.9999999 as datetime)' with 7 digit after decimal is working on sql server 2016 – mohit uprim Oct 25 '17 at 12:21
  • which management studio are you using? You should download SQL Mangement studio 17 then it will work for you. – SqlKindaGuy Oct 25 '17 at 13:07
  • @mohituprim As your not clear about which instance or management studio you use, i have tried different solutions which you can see in my answer. Hope this gives you an idea. – SqlKindaGuy Oct 25 '17 at 14:03

2 Answers2

1

Try the following in 2016 (notice the last digit)

select cast(2958463.99999996 as datetime)
John Cappelletti
  • 79,615
  • 7
  • 44
  • 66
1

You need to have the newest SQL Server Management studio available.

This is both on instances with Server version 2014 (12.0.4439.1) and 2016(13.0.4435.0).

NOTE:

SQL Server Management Studio 2017 only works with 7 digits on instance 2016(13.0.1601.5)

NOTE2:

SQL Server Management Studio 2014 only works with 7 digits on instance 2016(13.0.4435.0)

SQL Server Management Studio 2014 works with all digits on instance 2016(13.0.1601.5)

SQL Server Management Studio 2014 works will all digits on instance 2014(12.0.4439.1)

You can download the newest version here SQL Server Management Studio 2017

Tested on SQL Server instance 2016(13.0.4435.0) enter image description here

Tested on SQL Server instance 2014(12.0.4439.1) enter image description here

Tested on SQL Server Instance 2016(13.0.1601.5) enter image description here

Community
  • 1
  • 1
SqlKindaGuy
  • 3,501
  • 2
  • 12
  • 29