Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Load data into CSV file Expand / Collapse
Author
Message
Posted Monday, March 25, 2013 4:31 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Today @ 12:02 AM
Points: 44, Visits: 131
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
Post #1434811
Posted Monday, March 25, 2013 5:10 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 8:05 AM
Points: 1,729, Visits: 491
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
Post #1434828
Posted Monday, March 25, 2013 5:28 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 8:05 AM
Points: 1,729, Visits: 491
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() )

Post #1434834
Posted Monday, March 25, 2013 6:18 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Today @ 12:02 AM
Points: 44, Visits: 131
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() )
Post #1434859
Posted Monday, March 25, 2013 6:22 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 8:05 AM
Points: 1,729, Visits: 491
be wary of the Brackets, can you post the modified code with the column name in it?

Post #1434866
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse