Solved

SSIS: string to smalldatetime

Posted on 2010-08-30
5
1,595 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 50 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

770 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