What does this mean? LEN(TRIM(Weight)) == 0 ? (DT_

2019-06-10 02:50发布

问题:

Here's an expression for a derived column "ReplaceWeight"

LEN(TRIM(Weight)) == 0 ? (DT_STR,50,1252)NULL(DT_STR,50,1252) : (DT_STR,50,1252)Weight

I'm unclear about the syntax of the True portion of this IF statement...

I read this as "If the length of the trimmed column 'Weight' is zero, assign the derived column ReplaceWeight the a NULL value of type string?? ELSE convert the Weight column to a string and assign this value to the derived column"

The expression builder shows me that

NULL(DT_STR,50,1252) 

...returns a NULL value of the specified data type, DT_STR. This is a little weird to me, since I am used to NULL being a value that database columns of various types.

Am I to interpret that the following means "convert the null value of a STRING data type to a STRING data type?"

(DT_STR,50,1252)NULL(DT_STR,50,1252)

I would've thought this to be valid:

   LEN(TRIM(Weight)) == 0 ? NULL : (DT_STR,50,1252)Weight

Am I interpreting this code propertly?

回答1:

The first expression that you posted is correct.

The expression defines the data type of the derived column based on the values that it "sees" in the expression. You do not get the chance to manually define the data type of a derived column as you do when defining a table. So it is important that all possible return values have the data type defined correctly.

This is a function: NULL(DT_STR,50,1252)

The function returns NULL with the field type defined. You would think that this would be sufficient for SSIS, but you must also typecast the returned value, resulting in the somewhat redundant: (DT_STR,50,1252)NULL(DT_STR,50,1252)

If someone can explain why SSIS requires typecasting values that already have a data type defined, I'd be interested to hear the explanation.

Cheers, Peter



标签: ssis