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
 Int to Datetime convertion

Author  Topic 

Senthilkumar
Starting Member

2 Posts

Posted - 2007-11-19 : 12:26:33
Hi,

Actually i tried to convert the datetime value in yyyymmdd format from the int data type field.But except the first record it is looking fine.i cann't understand why this is happening? can you help me to resolve this problem?


Select ABECDT,case when ISDATE(cast(ABECDT as varchar))=1 then cast(ABECDT as varchar)
when len(cast(ABECDT as varchar))=8 then right(cast(ABECDT as varchar),4)+''+left(cast(ABECDT as varchar),2)+''+substring(cast(ABRDAT as varchar),3,2)
when len(cast(ABECDT as varchar))=7 then right(cast(ABECDT as varchar),4)+'0'+left(cast(ABECDT as varchar),1)+''+substring(cast(ABRDAT as varchar),2,2)
when len(cast(ABECDT as varchar))=6 then case when right(cast(ABECDT as varchar),2)<50 then '20' else '19' end
+right(cast(ABECDT as varchar),2)+''+substring(cast(ABECDT as varchar),3,2)+''+left(cast(ABECDT as varchar),2)
else NULL end from parm

Result i got it from the above query

Actual Value Result from the query

11012001 20011111
10012002 20021001
12011998 19981201
2011998 19980210
6012002 20020601

Can anyone help me to resolve this?

Thanks and Regards

Senthil


anonymous1
Posting Yak Master

185 Posts

Posted - 2007-11-19 : 14:23:54
you are building the date from multiple fields...ABRDAT looks like a typo in two places.
Go to Top of Page

Senthilkumar
Starting Member

2 Posts

Posted - 2007-11-19 : 15:15:56
Yes,I got it thanks for your help

quote:
Originally posted by anonymous1

you are building the date from multiple fields...ABRDAT looks like a typo in two places.


Go to Top of Page
   

- Advertisement -