Domanda

I am using SSIS package to import data from cvs file to table.

CVS File

Report_Date
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125
20140125

I want to convert in to 2014-02-05 date format.How can i do that in ssis Package.I tried with convert and casting but i was not successfull.Can any one help me ?

È stato utile?

Soluzione

You can use CONVERT( function to change that into date. For example

SELECT CONVERT(DATE,'20140210',112)

After you change it into date you can output it into any format that you want.

Read http://msdn.microsoft.com/en-us/library/ms187928.aspx for list of all styles that you can use for DATE when converting it. 112 stands for yyyymmdd format.

if date is stored as Numeric field you will need to convert it to VARCHAR before converting it to DATE,

SELECT CONVERT(DATE,CONVERT(VARCHAR(10),20140204),112)

Altri suggerimenti

I have not tested it with SSIS but if you look at TSQL output of these queries

Select Cast(20140125 AS DATETIME)

Select Cast('20140125' AS DATETIME)

First one failed with "Arithmetic overflow error converting expression to data type datetime." But second succeed.. It means if you convert first it to string and then to DateTime, it should work.. Will update you if able to do directly from SSIS

(DT_DBTIMESTAMP)(SUBSTRING([Report_Date],1,4) + "-" + SUBSTRING([Report_Date],5,2) + "-" + SUBSTRING([Report_Date],7,2))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top