<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'SSIS', 'T-SQL Tuesday', and 'Expression Language'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=SSIS,T-SQL+Tuesday,Expression+Language&amp;orTags=0</link><description>Search results matching tags 'SSIS', 'T-SQL Tuesday', and 'Expression Language'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>T-SQL Tuesday #001: A Couple SSIS Date Expressions</title><link>http://sqlblog.com/blogs/andy_leonard/archive/2009/12/08/t-sql-tuesday-001-a-couple-ssis-date-expressions.aspx</link><pubDate>Tue, 08 Dec 2009 16:26:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:19612</guid><dc:creator>andyleonard</dc:creator><description>&lt;P&gt;&lt;A href="http://sqlblog.com/blogs/adam_machanic/" target=_blank&gt;Adam Machanic&lt;/A&gt; is hosting this month's T-SQL Tuesday (the first!) on &lt;A href="http://sqlblog.com/blogs/adam_machanic/archive/2009/11/30/invitation-to-participate-in-t-sql-tuesday-001-date-time-tricks.aspx" target=_blank&gt;Date/Time Tricks&lt;/A&gt;. I thought I'd share a couple datetime SSIS Expressions I use regularly to format dates.&lt;/P&gt;
&lt;P&gt;First, I created an SSIS solution named ExpressionsTester, to which I added a data flow transformation, to which I added an OLEDB Source Adapter, Derived Column Transformation, and &lt;A href="http://sqlis.com/post/Trash-Destination-Adapter.aspx" target=_blank&gt;Trash Destination Adapter&lt;/A&gt;. I also created a Connection Manager aimed at AdventureWorks. I don't use the Connection Manager for anything - I simply need a connection manager to configure the OLEDB Source Adapter (someone needs to write a Trash Connection Manager...).&lt;/P&gt;
&lt;P&gt;When configured, it looks like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG style="WIDTH:311px;HEIGHT:384px;" src="http://vsteamsystemcentral.com/images/ext/TSQLTuesday_1.jpg" width=311 height=384&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The OLEDB Source (named "Now Source") is configured as shown:&lt;/P&gt;
&lt;P&gt;&lt;IMG style="WIDTH:838px;HEIGHT:724px;" src="http://vsteamsystemcentral.com/images/ext/TSQLTuesday_2.jpg" width=838 height=724&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The query is:&lt;/P&gt;
&lt;P&gt;Select getdate() as Now&lt;BR&gt;&amp;nbsp;-- Select '1/1/1972' as Now&lt;/P&gt;
&lt;P&gt;Inside the Derived Colum Transformation (named Derive DateTime Stuff)&amp;nbsp;I&amp;nbsp;create a couple columns based on the value of the Now column supplied by the Now Source source adapter. They are named StrDateOnly and StrLeadingZeroDateOnly:&lt;/P&gt;
&lt;P&gt;&lt;IMG style="WIDTH:876px;HEIGHT:724px;" src="http://vsteamsystemcentral.com/images/ext/TSQLTuesday_3.jpg" width=876 height=724&gt;&lt;/P&gt;
&lt;P&gt;The expression for StrDateOnly is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;(DT_STR,10,1252)((DT_STR,2,1252)MONTH(Now) + "/" + (DT_STR,2,1252)DAY(Now) + "/" + (DT_STR,4,1252)YEAR(Now))&lt;/P&gt;
&lt;P&gt;The expression for StrLeadingZeroDateOnly is:&lt;/P&gt;
&lt;P&gt;(DT_STR,10,1252)(((MONTH(Now) &amp;lt; 10 ? "0" + (DT_STR,1,1252)MONTH(Now) : (DT_Str,2,1252)MONTH(Now))) + "/" + ((DAY(Now) &amp;lt; 10 ? "0" + (DT_STR,1,1252)DAY(Now) : (DT_Str,2,1252)DAY(Now))) + "/" + (DT_Str,4,1252)YEAR(Now))&lt;/P&gt;
&lt;P&gt;Executing today (12/8/2009) produces the following output:&lt;/P&gt;
&lt;P&gt;&lt;IMG style="WIDTH:433px;HEIGHT:166px;" src="http://vsteamsystemcentral.com/images/ext/TSQLTuesday_4.jpg" width=433 height=166&gt;&lt;/P&gt;
&lt;P&gt;Note that both outputs are of the String data type (DT_STR in SSIS). This translates to the varchar data type&amp;nbsp;in SQL Server, but can be cast / converted as needed. Also note the StrLeadingZeroDateOnly places a leading zero before the day (08) while StrDateOnly does not - and that's the only real difference between the two expressions.&lt;/P&gt;
&lt;P&gt;I can hear you thinking: "Andy, why didn't you simple convert this in T-SQL?" I'm glad you asked! In this example, my source happens to be an OLEDB adapter, ostensibly connected to a relational database. This is not always the case. In SSIS, we regularly load data from flat files, XML, or custom sources that don't have a handy (or simple) way to coerce data types.&lt;/P&gt;
&lt;P&gt;:{&amp;gt; Andy&lt;/P&gt;</description></item></channel></rss>