Link to home
Start Free TrialLog in
Avatar of sqlagent007
sqlagent007Flag for United States of America

asked on

SSIS 2016 how can I use the derived column or data conversion to convert a string value of "3/1/2017" to SMALLDATETIME?

I thought this would be easy and I am able to do this with ease in TSQL, but I am struggling in SSIS. I have a flat file (.txt) that has a column named [DATE], this column puts the start_date and end_date together like this: "03/01/2017 - 04/01/2017". I am able to perform the conversion I need with a simple CAST in TSQL like this:
declare @test varchar (50) ='03/02/2017 - 04/01/2017'

select cast(left(@test,10) as smalldatetime) as Date_Start

select cast(right(@test,10) as smalldatetime) as Date_End

Open in new window


I have tried using the [derived column] and [data conversion] in SSIS with no luck. I keep getting this error when trying to insert into the OLE DB destination: "The value could not be converted because of a potential loss of data".

Please help experts....
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

with dates it is always problematic

create a derived column and use

Date_Start -> (DT_DBTIMESTAMP)(left(@test,10))

create a derived column and use

Date_end -> (DT_DBTIMESTAMP)(right(@test,10))
Avatar of sqlagent007

ASKER

Thanks @Pawan, I will be testing this later today.
I keep getting this error:
 Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "Derived Column" failed because error code 0xC0049064 

Open in new window

can you show exactly what you are doing?
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!