I am developing an SSIS 2008 package and I am trying to create a Derived Column transformation. But when I go to the Expression editor and try this expression it gives me alot of errors. I have tried various differentiations of this but all have resulted in errors. I need one of you SQL experts to point out a better expression!
ISNULL(WITHDRAWAL_DATE)||TRIM(WITHDRAWAL_DATE)==""?NULL:CAST(WITHDRAWAL_DATE AS DATETIME)
So I want this WITHDRAWAL_DATE input String datatype to be compared to an empty string--if it is empty I want it to become Null, otherwise to be cast as a date.
Thanks guys for your helps. I am so confused! WITHDRAWAL_DATE is a DATE data type input in the source XML file and now I have it as a STRING data type in my XSD file. Ultimately the problem is that some of the Withdrawal_Date fields in my XML source data are empty. So I want to insert Null values into my database for these records.
What data type do I need to specify in my XSD, XLST, and SQL output table? And it doesn't matter to me if I use Data Conversion task or Derived Column Xform but since I am new to these, could you send me expression syntax?
@BobS: when I ran with your updated solution, I received error: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value
So when I googled datetime2 datatype it looks like this is a new data type that supports larger time/date fields. So I modified my SQL table to use DATETIME2 instead for this field and modified your cast expression below to use DATETIME2 but then output of transform didn't change accordingly.
I also tried changing WITHDRAWAL_DATE to datetime for all files and then changing SQL Table to say NOT NULL for this field. But this also gave me errors.