SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


convert the datatype string to date


convert the datatype string to date

Author
Message
vasu.ssis
vasu.ssis
Old Hand
Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)

Group: General Forum Members
Points: 353 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
John H Marsh
John H Marsh
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3375 Visits: 1467
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
vasu.ssis
vasu.ssis
Old Hand
Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)

Group: General Forum Members
Points: 353 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
GilaMonster
GilaMonster
SSC Guru
SSC Guru (227K reputation)SSC Guru (227K reputation)SSC Guru (227K reputation)SSC Guru (227K reputation)SSC Guru (227K reputation)SSC Guru (227K reputation)SSC Guru (227K reputation)SSC Guru (227K reputation)

Group: General Forum Members
Points: 227071 Visits: 46335
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, MVP, M.Sc (Comp Sci)
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


John H Marsh
John H Marsh
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3375 Visits: 1467
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
vasu.ssis
vasu.ssis
Old Hand
Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)Old Hand (353 reputation)

Group: General Forum Members
Points: 353 Visits: 90
its working fine

Thanks to GilaMonster and everyone who reply this qustion
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search