Solved

Derive single datetime2 from separate date and time columns

Posted on 2011-02-25
6
832 Views
Last Modified: 2012-05-11
I am importing a vast amount of data into Sql Server with SSIS.  In the input data, which is in CSV format, there are separate date and time columns.  The time has millisecond precision. I want to derive a single datetime2 output column.  
I have tried in SSIS to use the derived column transformation as follows:
(DT_DBTIME2,3)[Date]+ (DT_DBTIME2, 3) [Time]
But this cannot be evaluated.

Does anyone have an idea how to simply derive a single datetime2 column from separate input date and time columns in a CSV?  

I thought of casting date and time as strings, concatenating them with a space, and then casting the result as a datetime2(3) column.  This seems inelegant and slow however.  Any better approaches?
0
Comment
Question by:gnf
  • 4
  • 2
6 Comments
 
LVL 17

Expert Comment

by:dbaSQL
ID: 34981832
You're going to need to concatenate the two values, and I'm pretty sure you can just do this with a derived column.  

Add the 'Derived Column' transform to your data flow tab, then double-click it.

Drived column name     whatever you want the new column to be named
Drived Column             choose the 'Add as new field' option
Expression                [datefield1]  + " "  + [datefield2]      
Datatype                   Database Date

Remember, the expression is case sensitive.
0
 

Accepted Solution

by:
gnf earned 0 total points
ID: 34983298
I had hoped there would be a better solution than concatenating strings but maybe there isn't.  I use a regular expression in SSIS as follows:

(DT_DBTIMESTAMP2,3)(SUBSTRING([Date],1,4) + "-" + SUBSTRING([Date],5,2) + "-" + SUBSTRING([Date],7,2) + " " + [Time])
0
 
LVL 17

Expert Comment

by:dbaSQL
ID: 34983358
Well, there may be another way, but the concatenated value is what I am familiar with.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:gnf
ID: 35010346
Question closed
0
 

Author Comment

by:gnf
ID: 35010350
Closed question.
0
 

Author Closing Comment

by:gnf
ID: 35045627
Wished there was a cleaner way, but it seems there isn't.  Have to concatenate strings.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL trigger 5 23
SQL, add where clause 5 24
MS SQL AND PASSING A TABLE NAME TO A SPROC 5 18
Casting is giving error in sql server 3 12
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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…

830 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