?
Solved

Arithmetic overflow error converting expression to data type smalldatetime!!!

Posted on 2006-06-12
2
Medium Priority
?
1,954 Views
Last Modified: 2012-06-22
Hi! i have a table that has a column with dates that where stored in a decimal type field! ... i've converted that columnn to nvarchar(50) and then parsed the the dates from '20040225' to
'2004-02-25' . That went ok. (the dates with the '20040225' where in a decimal type field...go figure!) ... but now ... after parsing the dates to the '2004-02-25' format, when i try to change the column from nvarchar(50) to smalldatetime i get the error: Arithmetic overflow error converting expression to data type smalldatetime.

I know this has something to do with some wrong date around somewhere. How can i find the wrong dates in my table? is there a query to do it? i know there is! ... please help!
0
Comment
Question by:xjpmauricio
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 16883864
you should create a additional column (with datetime), and update it:

update yourtable
  set new_field=  convert(datetime, yourfield, 120)

if that gives the same error, you need to identify the rows.
I would load the field into a test table:

create table test_date_values ( id int, year_value varchar(4), month_value varchar(2), day_value varchar(2))
insert into test_date_values select id, substring(yourfield, 1,4), substring(yourfield, 6,2), substring(yourfield, 9,2) from yourtable

and how, check the validity of the dates...
0
 
LVL 1

Author Comment

by:xjpmauricio
ID: 16883918
--FIND INVALID DATES

create table test_date_values ( id int, year_value varchar(4), month_value varchar(2), day_value varchar(2))
insert into test_date_values select id,
substring(DATA_SITUACAO, 1,4), substring(DATA_SITUACAO, 6,2), substring(DATA_SITUACAO, 9,2) from FARQ_007D

select * from test_date_values where month_value  > 31

...the solution whas so simple that i think i'm such a dum bustard!!! god!....

thanks a lot!...
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question