Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

convert the datatype string to date Expand / Collapse
Author
Message
Posted Tuesday, August 19, 2008 10:31 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, December 19, 2008 9:30 AM
Points: 23, Visits: 90
hi guys,

i am using sql server 2005 to convert datatype string to date for that i create one new column(datetime) in my table and i did

update tablename set newcolumn=oldcolumn

but it shows following error

Arithemetic overflow error converting to data type date time
the statement has been terminated

i am traying these for long 2 days

any help appricated
Post #555488
Posted Tuesday, August 19, 2008 11:57 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, April 22, 2014 6:56 AM
Points: 1,330, Visits: 1,434
Hello,

I would guess it is an issue with the format that the data is stored in, in the old column.

Is it always the same format e.g. mm/dd/yyyy? Can you post a sample of the data in the old column?

Regards,

John Marsh


www.sql.lu
SQL Server Luxembourg User Group
Post #555509
Posted Wednesday, August 20, 2008 12:22 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, December 19, 2008 9:30 AM
Points: 23, Visits: 90
Hi john

it is my sample data of old column

primary key oldcolumn
----------- ---------
023456781 20050428
023456782 20040112
023456783 20061228
023456784 00000000
023456785 20050428
023456786 20060409
023456787 00000000
023456788 20060607
023456789 20049718
Post #555517
Posted Wednesday, August 20, 2008 12:35 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 8:37 AM
Points: 40,596, Visits: 37,053
I think the problem is those 00000000 values. They aren't convertable to datetime.

Try this
update tablename set newcolumn=CAST(oldcolumn AS DATETIME) WHERE ISDATE(oldcolumn)=1




Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #555524
Posted Wednesday, August 20, 2008 12:44 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, April 22, 2014 6:56 AM
Points: 1,330, Visits: 1,434
Hello,

Yes, "GilaMonster" is right. It is the zero filled values that cause the problem.

There is the question of what you want to do in the case of zeros? Do zeros represent a non existent value for the row? In this case you might want the new column to contain a Null.

Regards,

John Marsh


www.sql.lu
SQL Server Luxembourg User Group
Post #555529
Posted Wednesday, August 20, 2008 2:44 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, December 19, 2008 9:30 AM
Points: 23, Visits: 90
its working fine

Thanks to GilaMonster and everyone who reply this qustion

Post #555602
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse