Solved

Derive single datetime2 from separate date and time columns

Posted on 2011-02-25
6
826 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now