Avatar of barrontech
barrontech

asked on 

Date format in SSIS using Derviced Columns

I'm trying to get my DTS packages converted over to SSIS.  I have a package that has a datetime field that when converting to a text file needs to be in a format of MMDDYY.  Simple in DTS, but change is good eh?  I can run this query against my table in SQL 2005 and the output is exactly the way I want it;

REPLACE(CONVERT(CHAR(8),ADJ_DATE,10),'-','')

Output example.  043008 = April 30, 2008

When trying to add this statement in my expression as a derived column I am getting an error message.  It's saying function CHAR not recognized.  Any ideas on how to make this work in SSIS?
Thank you in advance.
Microsoft SQL Server

Avatar of undefined
Last Comment
nmcdermaid
ASKER CERTIFIED SOLUTION
Avatar of nmcdermaid
nmcdermaid

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of nmcdermaid
nmcdermaid

Avatar of nmcdermaid
nmcdermaid

This one has a big mutha case statement to work out the month name... this implies that the first option above is best as there doesn't appear to be a nice way to format to a month name with a format string.... unfortunate.

http://wiki.sqlis.com/default.aspx/SQLISWiki/ExpressionDateFunctions.html


OK I'm finished  :)
Avatar of barrontech
barrontech

ASKER

Thanks - I ended up using solution #1.  Was very easy.  Thanks for the links too.  Good information for a beginning SSIS person.
Avatar of barrontech
barrontech

ASKER

I kinda jumped the gun.  Still having a minor issue.  The conversion itself took place just fine.  However, if you look at the datatype in the metadata tab of Data Flow Path Editor it has a data type of DT_STR and a length of 8000.  I need the length to be 6.  How do I change the length to 6 from 8000? I thought the CHAR(8) function would do that?
Avatar of nmcdermaid
nmcdermaid

Possibly the REPLACE is casting to an unknown (8000) length again.


You can try:

1. Another CHAR(8) around the outside: CONVERT(CHAR(8),(REPLACE(CONVERT(CHAR(8),ADJ_DATE,10),'-',''))
2. Using a data type conversion step to convert from DT_STR(8000) to DT_STR(8)

I'd recommend the first since you've already started down the T-SQL track.
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo