Load data into CSV file

  • I am fetching data from sql server 2005 table, there are 3 columns D1,D2,D3 which are in datetime datatype. Into SSIS i have used oledb source to read all the data from a table and then Flat File destination to load into CSV file using flat file connection manager.

    However the data load is successfull but the column D1,D2,D3 are population as below.

    The source value in table are

    D1: 2011-02-03 00:00:00.000

    D2: 2011-02-03 09:53:41.740

    D3: 2011-12-15 14:42:09.490

    The CSV file column format for D1,D2, D3

    D1: 2/3/2011 0:00

    D2:2/3/2011 9:53:42 AM

    D3:12/15/2011 2:42:09 PM

    But i need into to load into mm/dd/yyyy or mm-dd-yyyy format only into CSV file. please help

  • When i have had to do this in the past i have had to use a derived column which is of type DT_STR and then write a fairly complex expression to fill the column.

    you need to use an if statement to work out when a day or month is less than 10 and suffix a 0 to the ouput datepart then you'll end up with what your after.

    if you can do without the suffixed zeros the expression is far easier to implement. i will see if i can dig one out but give it a go yourself there is a datepart function similar to that SQL but within SSIS expressions

  • This should do it, exchange GETDATE() for the date you deriving the column from. Apply the Logic to the Hours/minutes/seconds if you need to suffix 0's to that also.

    (DATEPART( "Month", GETDATE() )<10?"0"+(DT_WSTR, 250)DATEPART( "Month", GETDATE() ):(DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Month", GETDATE() ))

    +"/"+

    (DATEPART( "Day", GETDATE() )<10?"0"+(DT_WSTR, 250)DATEPART( "Day", GETDATE() ):(DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Day", GETDATE() ))

    +"/"+(DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Year", GETDATE() )

    +" "+(DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Hour", GETDATE() )

    +":"+(DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Minute", GETDATE() )

    +":"+(DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Second", GETDATE() )

  • Thanks for replying.

    I used the below code into derived column expression but it says invalid expression, invlaid token. i replaced the getdate() with the column name i need to convert.

    (DATEPART( "Month", GETDATE() )<10?"0"+(DT_WSTR, 250)DATEPART( "Month", GETDATE() )DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Month", GETDATE() ))

    +"/"+

    (DATEPART( "Day", GETDATE() )<10?"0"+(DT_WSTR, 250)DATEPART( "Day", GETDATE() )DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Day", GETDATE() ))

    +"/"+(DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Year", GETDATE() )

    +" "+(DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Hour", GETDATE() )

    +":"+(DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Minute", GETDATE() )

    +":"+(DT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Second", GETDATE() )

  • be wary of the Brackets, can you post the modified code with the column name in it?

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply