SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Load data into CSV file


Load data into CSV file

Author
Message
Karan_W
Karan_W
SSC-Addicted
SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)

Group: General Forum Members
Points: 448 Visits: 135
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
Terry300577
Terry300577
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2305 Visits: 516
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
Terry300577
Terry300577
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2305 Visits: 516
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()  )SadDT_WSTR, 250) (DT_WSTR, 250)DATEPART( "Month", GETDATE()  ))
+"/"+
(DATEPART( "Day", GETDATE() )<10?"0"+(DT_WSTR, 250)DATEPART( "Day", GETDATE() )SadDT_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() )


Karan_W
Karan_W
SSC-Addicted
SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)SSC-Addicted (448 reputation)

Group: General Forum Members
Points: 448 Visits: 135
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() )
Terry300577
Terry300577
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2305 Visits: 516
be wary of the Brackets, can you post the modified code with the column name in it?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search