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

This is a discussion on Adding a value to a 'datetime' column caused overflow. within the sqlserver-tools forums in Microsoft SQL Server category; This is a simple select statement where I am trying to convert a Julian date. Where one of the fields is zero I get this error. My Select statement is: select DATEPART(yy, DATEADD(dd, date_last_inv - 722815, '1/1/80'))as date_last_inv, DATEPART(yy, DATEADD(dd, date_last_cm - 722815, '1/1/80')) as date_last_cm, DATEPART(yy, DATEADD(dd, date_last_pyt - 722815, '1/1/80'))as date_last_pyt from aractcus the date_last_inv, cm, pyt is a int column. How can I get around the zero's. The full error is: Server: Msg 517, Level 16, State 1, Line 1 Adding a value to a '...

Go Back   Database Forum > Microsoft SQL Server > sqlserver-tools

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-26-2008, 05:23 PM
Default Adding a value to a 'datetime' column caused overflow.

This is a simple select statement where I am trying to convert a Julian date.
Where one of the fields is zero I get this error.

My Select statement is:

select
DATEPART(yy, DATEADD(dd, date_last_inv - 722815, '1/1/80'))as date_last_inv,
DATEPART(yy, DATEADD(dd, date_last_cm - 722815, '1/1/80')) as date_last_cm,
DATEPART(yy, DATEADD(dd, date_last_pyt - 722815, '1/1/80'))as date_last_pyt
from aractcus


the date_last_inv, cm, pyt is a int column. How can I get around the zero's.

The full error is:

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



Reply With Quote
  #2  
Old 08-27-2008, 11:26 AM
Default RE: Adding a value to a 'datetime' column caused overflow.

Try it,

SELECT
CASE WHEN DATE_LAST_INV>640000 THEN DATEPART(YY, DATEADD(DD, DATE_LAST_INV -
722815, '1/1/80')) ELSE 0 END AS DATE_LAST_INV,
CASE WHEN DATE_LAST_INV>640000 THEN DATEPART(YY, DATEADD(DD, DATE_LAST_CM -
722815, '1/1/80')) ELSE 0 END AS DATE_LAST_CM,
CASE WHEN DATE_LAST_INV>640000 THEN DATEPART(YY, DATEADD(DD, DATE_LAST_PYT -
722815, '1/1/80')) ELSE 0 ENDAS DATE_LAST_PYT
FROM ARACTCUS

Reply With Quote
  #3  
Old 08-27-2008, 01:06 PM
Default RE: Adding a value to a 'datetime' column caused overflow.

Thank you.

"Tariq" wrote:

> Try it,
>
> SELECT
> CASE WHEN DATE_LAST_INV>640000 THEN DATEPART(YY, DATEADD(DD, DATE_LAST_INV -
> 722815, '1/1/80')) ELSE 0 END AS DATE_LAST_INV,
> CASE WHEN DATE_LAST_INV>640000 THEN DATEPART(YY, DATEADD(DD, DATE_LAST_CM -
> 722815, '1/1/80')) ELSE 0 END AS DATE_LAST_CM,
> CASE WHEN DATE_LAST_INV>640000 THEN DATEPART(YY, DATEADD(DD, DATE_LAST_PYT -
> 722815, '1/1/80')) ELSE 0 ENDAS DATE_LAST_PYT
> FROM ARACTCUS
>

Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 07:52 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.