Avatar of running32
running32
 asked on

Adding a value to a 'datetime' column caused overflow.

i am getting the error "Adding a value to a 'datetime' column caused overflow."   when I try and run this statement.  DATEADD(dd, - 365, p.LASTMISSEDAPPT) < pl.PLDATE.  how can I change DATEADD(dd, - 365, p.LASTMISSEDAPPT) to avoid this.

Thanks
Microsoft SQL Server

Avatar of undefined
Last Comment
running32

8/22/2022 - Mon
Guy Hengel [angelIII / a3]

what are values in the 2 fields? you might hit min value of date ...what about:
 p.LASTMISSEDAPPT < dateadd(dd, 365, pl.PLDATE)


resp:

p.LASTMISSEDAPPT < dateadd(year, 1, pl.PLDATE)

Open in new window

aledev

Waht type is p.LASTMISSEDAPPT?

If p.LASTMISSEDAPPT is a float "representing" a date, then this value is likely
to be too high. If it exceeds 2936549 you will get an out or range error
(or similar error). If it represents a date, you should cast it to a
datetime.
running32

ASKER
Example of a field is the value of the fields could be 9/7/2010.  It still does it when I cast the value as datetime 101.  thanks
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
aledev

have you tried this?

DATEADD(year, -1, p.LASTMISSEDAPPT)
running32

ASKER
yes, still gives me the same error.  Thanks
aledev

There are any rows in your data table with this value in that field?

'1900-01-01 00:00:00'
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
running32

ASKER
NO the default date looks like 3/2/1753 or NULL
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mastoo

You might look for this to find the problem data:

Select * from yourtable
  Where IsDate(p.LASTMISSEDAPPT) = 0
aledev

maybe the minimum SQL DateTime Value is 1/1/1753. Substruct one year to fields with the value you have mentioned ("3/2/1753") throw the exception
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
running32

ASKER
angelIII, I tried your suggestion but it didn't work still gave the error

Server: Msg 517, Level 16, State 1, Line 1
Adding a value to a 'datetime' column caused overflow.