views:

54

answers:

3

I just had to write the most redonkulous expression in an SSIS Derived Column to get dates formatted like "01-JAN-2010".  It lookes like this:

      alt text

There's got to be a better way... isn't there?

+4  A: 

Consider using a script component and then Row.stringcol = Row.datecol.ToString("dd-MMM-yyyy") to populate a new string column in the data flow.

Cade Roux
+2  A: 

If you want to use expressions, you could use this instead:

RIGHT("0" + (DT_WSTR, 2)DAY(ASSIGNMENT_BEGIN_DATE), 2) + "-" + SUBSTRING("JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC", (3 * MONTH(ASSIGNMENT_BEGIN_DATE)) - 2, 3) + (DT_WSTR, 4)YEAR(ASSIGNMENT_BEGIN_DATE)

Didn't say it was better. It's just different and shorter. Use a Script as Cade suggested if you want better control.

Todd McDermid
+3  A: 

Okay, now I feel like a Donkey. The easy solution is to make my Data Source a select statement in which I simply handle that column like this:

     SELECT to_char(assignment_begin_date, 'dd-MON-yyyy') assignment_begin_date FROM ...

The RDBMS is Oracle, btw.

Then I don't need to do a derived column or a script.

I have self-administered a dope-slap for not thinking of it earlier. Thanks to all for the help.

theog
I assumed you were going out of SQL Server (which doesn't have a very easy way to do that particular format), and I had written a suggestion of formatting it on the way out, but then decided doing it in T-SQL was still too messy. I assume you aren't going into SQL Server, because then I would ask why you are formatting this date into text at all.
Cade Roux
Thanks Cade, and sorry my buffoonery wasted your time. It's going into a flat file, so that's why the unusual formatting is needed.
theog
@theog - So not even going through SQL Server at all?
Cade Roux
@Cade, the data may end up in a SQL Server db in another process, but this particular package is just extracting it from Oracle and putting it into a flat file on a file server. Otherwise I'd just Select from Oracle and Insert into SQL Server in a Data Flow Task.
theog