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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 date in string format

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-05-17 : 04:35:22
I get a Flat file with date format as 070516 in col007
Move it to a temp table into a varchar datatype col named old_date

I Update new_date column of data type datetime based on the old_date varchar datatype
UPDATE tbl_new
SET new_date = convert(datetime,right(Col007,2) + '-'+ substring(Col007, 3,2) +'-'+ left(Col007,2))

this is the error am getting

Move from
Error string: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Any help would be great to get the string date into a datatype of datetime

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-17 : 04:39:04
try
convert(datetime, col007, 12)



KH

Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-05-17 : 04:55:20
Thats returning a error also for me..

this is what i used

UPDATE tbl_new
SET new_date = convert(datetime,right(Col007,2) + '-'+ substring(Col007, 3,2) +'-'+ left(Col007,2),12)
Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2007-05-17 : 05:01:57
No need to use substring etc
use this
UPDATE tbl_new
SET new_date = convert(datetime,Col007,12)
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-05-17 : 05:20:37
Yep that worked, the funny thing about the old script it did work for about 2 weeks and did work when i ran the job manually from the dts package but when i scheduled the job it failed..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-17 : 07:35:23
You can customise this Proper_date function
http://sqlteam.com/forums/topic.asp?TOPIC_ID=82164

Madhivanan

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

- Advertisement -