Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Arithmetic overflow error

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2009-05-28 : 13:39:52
Getting message:
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type datetime.

When trying to run script below. I want all records that have a doc_dt greater than the year 2006


SELECT
source, ord_no, ctl_no, line_no, lev_no, seq_no, from_source, from_ord_no, from_ctl_no, from_line_no, from_lev_no, from_seq_no, item_no, item_filler, par_item_no, par_item_filler, loc, trx_dt, trx_tm, doc_dt, doc_type, doc_ord_no, doc_source, cus_no, vend_no, prod_type, quantity,old_quantity, unit_cost, old_unit_cost, new_unit_cost, price, build_qty, build_qty_per, amt, landed_cost, receipt_ord_no, status, jnl, batch_id, user_name, id_no, comment, filler_0003, trx_qty_bkord, promise_dt, rev_no, deall_amt, filler_0004, A4GLIdentity
FROM iminvtrx_sql
where year(doc_dt) > (year(getdate())-3)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-28 : 13:42:39
what datatype is doc_dt column?


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-28 : 13:45:54
whats the datatype of doc_dt?
Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2009-05-28 : 14:05:19
OH! Working with a different database than I'm used to. It was int and not datetime.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-28 : 14:08:01
so what does int value represent? days since 0 ie. 1 jan 1900?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-28 : 14:12:17
year(cast(doc_dt as varchar(8))) >


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-29 : 02:14:50
quote:
Originally posted by Peso

year(cast(doc_dt as varchar(8))) >


E 12°55'05.63"
N 56°04'39.26"



Did you mean converting to datetime?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-29 : 02:30:20
No, to varchar. If date is stored as integer in the format "yyyymmdd", casting to varchar and taking the year out of that will do.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-29 : 05:25:58
Ok. Fine

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -