I'm trying to concatenate some strings using expression builder within SSIS depending on a variable being null or not but get the following error message
"String1" + ISNULL( #[User::ReservingAnalysisClassCodes]) ? "String2" : "String3"
Per Nick from the comments, this should work:
"String1" + (ISNULL( #[User::ReservingAnalysisClassCodes]) ? "String2" : "String3")
SSIS is trying to concatenate "String1" + ISNULL( #[User::ReservingAnalysisClassCodes] which is why it's throwing an error.
Related
I have the following query :
SELECT '31/12/1999 00:00:00' AS ODSUpdatedate
I want to ass a derived column ODSUpdatedate like below :
I am getting this following error :
Change the expression to :
(DT_DATE) "31/12/1999 00:00:00"
In SSIS derived column I need to check if a Date field is empty or null, I'm using this expression but I got an error:
TRIM([date field]) == "" ? NULL(DT_DATE) : TRIM([date field])
The field is of DT_DATE data type. What's wrong in that?
I've used expressions like this successfully:
TRIM(String_field) == "" ? NULL(DT_WSTR,255) : TRIM(String_field)
You are combining data types (if true is a date and false is a string).
This is the correct formula:
TRIM([date field]) == "" ? NULL(DT_DATE) : (DT_DATE)TRIM([date field])
I am assuming [date field] is a string.
Concerning the error, it is related to the derived column result data type, since in conditional operators (?:) both true and false expression must generate the same data type.
In addition, your expression doesn't check for NULL values, you should use the following expression:
TRIM(REPLACENULL([date field],"")) == "" ? NULL(DT_DATE) : (DT_DATE)TRIM([date field])
Also, you have to make sure that [date field] can be parsed as date, so (DT_DATE)TRIM([date field]) will not throw an exception, you can use the error output to handles the value that doesn't contain a valid date.
I need to cleanup a set of companies name by replacing : INC, LTD, LTD. , INC. , others, with a empty space when they are individual words ( with one blank space before the word i.e. Incoming INC) and not letters part of company name i.e. INComing Money.
The logic I tried :
case
when FINDSTRING([Trade Name]," INC",1) > 0 then REPLACE([Trade Name]," INC","")
when FINDSTRING([Trade Name]," LTD",1) > 0 then REPLACE([Trade Name]," LTD","")
ELSE [Trade Name]
I tried SSIS expresion in a derived column :
FINDSTRING( [Trade Name] ," INC",1) ? REPLACE([Trade Name]," INC","") :
FINDSTRING([Trade Name]," LTD",1) ? REPLACE([Trade Name]," LTD",""):
The error received:
Error at Data Flow Task [Derived Column [1]]: Attempt to find the
input column named "A" failed with error code 0xC0010009. The input
column specified was not found in the input column collection.
In a similar case it is easier to use a Script Component to clean this column, you can simply split the column based on spaces then re concatenate the parts that are not equal to INC, you can use the following method to do that, or you can simple use RegEx.Replace() method to replace values based on regular expressions:
string value = "";
string[] parts = Row.TradeName.Split(' ');
foreach(string str in parts){
if(str != "INC"){
value += " " + str;
}
}
Row.outTradeName = value.TrimStart();
Is it possible to use a variable in the assignfile command?
Eg.
f : Textfile ;
sFile : string ; {contains 'MyFile.txt' as content}
...
cFileDir = 'C:\Users\User\Desktop\Data Engine\Data\Country' ;
...
Assignfile(f, cFileDir + '\' + sFile) ;
...
I appreciate your help very much. if it's unclear I'll edit the question to add more details.
Is it possible to use a variable in the AssignFile command?
Yes.
The second parameter of AssignFile has type string.
The expression cFileDir + '\' + sFile has type string.
FWIW, AssignFile is known as a function rather than a command. Getting on top of terminology like this will help you learn the language more effectively.
what is the SSIS equivalent expression(Derived Column component) of the below SQL expression
cast(CASE WHEN len(cast(KPI as varchar(3))) > 2 THEN
CASE substring(cast(KPI as varchar(3)),3,1)
WHEN 1 then left(cast(KPI as varchar(3)),1) + 'a'
WHEN 2 then left(cast(KPI as varchar(3)),1) + 'b'
WHEN 3 then left(cast(KPI as varchar(3)),1) + 'c'
WHEN 4 then left(cast(KPI as varchar(3)),1) + 'd'
END
ELSE cast(KPI as varchar(3))
END as VarChar(3)) as 'ColumnName'
here Kpi column is a double precision floating point data type...
one major thing i have observed here is LEFT String function is missing from SSIS Expression Builder.
SSIS experts please have a look..
I have been trying around 1 hour on my system..finally found the answer..Hope it would be useful to somebody else
created a new column,NewKPI and converted that to dt_str in dataconversion componet (as mentioned by Justin )
(DT_STR,3,1252)(LEN(NewKPI) <= 2 ? NewKPI : (SUBSTRING(NewKPI,3,1) == "1") ? "2A" : (SUBSTRING(NewKPI,3,1) == "2") ? "2b" : (SUBSTRING(NewKPI,3,1) == "3") ? "2c" : (SUBSTRING(NewKPI,3,1) == "4") ? "2d" : NULL(DT_WSTR,3))
(I have used substring instead of Left)
Thanks all for the help