SSIS Script Component Transformation C# Code Date Conversion -


i'm creating ssis packages import large fixed width text documents , need transform various fields. 1 such field represents dates , 8 characters wide. format "yyyymmdd" , this:

somedatefield 20130415 20110122 19891023 

however, fields have blank spaces, , have zeroes 00000000. cannot converted date should return null value. i'm not allowed substitute date 1/1/1900.

after futilely trying convert date field expressions, turned c# script transformation.

my input column called ssolddate , readonly. i've configured output called solddate of dt-dbdate data type.

the code came works is:

datetime vardate;         bool isparsed;          isparsed = datetime.tryparseexact(row.ssolddate, "yyyymmdd", cultureinfo.invariantculture, datetimestyles.none, out vardate);         if (isparsed)         {             row.solddate = vardate;         }         else         {             row.solddate_isnull = true;         } 

i follow other date fields 1 in text import repeating code in same script component , substituting other field names. don't have repeat variable declarations however.

even though works, going have repeat process lot, , wanted make sure expedient way of performing kind of check , conversion. there more concise way of achieving same thing?

is there more performant way?

is there simple way encapsulate logic in custom method or function make process easier?

david,

one thing i've done in past create (or have create you) .net assembly code use repeatedly. should able reference assembly in of scripts write.

i've used sql server 2008\2008 r2 bids. haven't tried 2012 bids yet. let me know if need more info. might write blog this.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -