?
Solved

Derive single datetime2 from separate date and time columns

Posted on 2011-02-25
6
Medium Priority
?
837 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Suggested Courses

762 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