Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SSIS: string to smalldatetime

Posted on 2010-08-30
5
Medium Priority
?
1,857 Views
Last Modified: 2013-11-10
I have a date & timestamp loading in from a text file (YYYYMMDDHHMMSS) that I need to convert to a dbtimestamp and match against a smalldatetime field in a table.

I'm loading the data in as a string and then via the Derived column tool I do a DT_DBTEIMESTAMP type cast (into the format as I see it in a sql statement YYYY-MM-DD HH:MM:00), but the process keeps erroring out at that step. Is the internal format different (MMDDYYYHHMMSS) or what am I missing?

Thanks!
0
Comment
Question by:wppiexperts
  • 3
5 Comments
 

Author Comment

by:wppiexperts
ID: 33560319
As an additional note: the type cast format I'm using is:
(DT_DBTIMESTAMP)(SUBSTRING(IntervalStartDateTime,5,2) + "-" + SUBSTRING(IntervalStartDateTime,7,2) + "-" + SUBSTRING(IntervalStartDateTime,1,4) + " " + SUBSTRING(IntervalStartDateTime,9,2) + "-" + SUBSTRING(IntervalStartDateTime,11,2) + ":00")

and this fails during execution.

If I remove the portion of the datatype that represents time (SUBSTRING(IntervalStartDateTime,9,2) + "-" + SUBSTRING(IntervalStartDateTime,11,2) + ":00") then this step works fine, so am I not building the datetime value properly?
0
 
LVL 21

Expert Comment

by:Jason Yousef, MS
ID: 33560419
1-Why would you set 50 points to the question while you're a Premium Service Member and have no limit on points !

2-what's the error msg you're getting? the answer should be obvious in the error msg.

3-DT_DBTEIMESTAMP Cast will cast from "date" to DT_DBTEIMESTAMP, and you're not sending "date" type in the pipe!

4-Try a Derived COLUMN Transfer and type this to convert the YYYYMMDD to YYYY-MM-DD
in the expression you must have

Derived Column name Derived column Expression
Date  <Replace Date> SUBSTRING ([DATE] , 1 , 4) + "/" +SUBSTRING ([DATE] ,5 , 2) + "/" +SUBSTRING ([DATE] ,7 , 2)



5-then cast the above to DT_DBTEIMESTAMP


so the final query should be:

(DT_DBTIMESTAMP)(SUBSTRING ( [Stmt From]  , 1 , 4) + "/" +SUBSTRING ([Stmt From] ,5 , 2) + "/"+ SUBSTRING ([Stmt From] ,7 , 2))


hope that helps :)
0
 

Author Comment

by:wppiexperts
ID: 33560813
thats what I'm finding a bit confusing about the conversion process. If my original value was "YYYYMMDDHHMMSS" and I build an expression in the Derived column transformation in the format "YYYY-MM-DD HH:MM:00" it fails using the DT_DBTIMESAMP, but if I remove the time reference, it works fine. I was under the assumption that if I passed the function a valid datetime in the proper format, it would change it from a string to a datetime datatype.

so, I guess my underlying questions are:
1. How do I use the derived column transformation to take a string and create a datetime value
2. Based on the expression I posted above, what am I doing wrong in that it doesn't recognize it as a datetime?

0
 
LVL 30

Accepted Solution

by:
Reza Rad earned 200 total points
ID: 33561548
what about this one:

(DT_DBTIMESTAMP)(SUBSTRING(IntervalStartDateTime,5,2) + "-" + SUBSTRING(IntervalStartDateTime,7,2) + "-" + SUBSTRING(IntervalStartDateTime,1,4) + " " + SUBSTRING(IntervalStartDateTime,9,2) + ":" + SUBSTRING(IntervalStartDateTime,11,2) + ":00")

try it.


0
 

Author Closing Comment

by:wppiexperts
ID: 33562128
perfect!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question