Datatype mismatch error in ssis - ssis

I am retrieving some columns from some tables(below two are responsible for errors)
CUSTOMER_ID - numeric(9)
INCIDENT_ID - int(4)
and moving the results to foreach loop container(used derived transformation before moving results into record set i.e., CUSTOMER_ID - DT_NUMERIC,INCIDENT_ID - DT_I4) but i end up with these two errors
ForEach Variable Mapping number 3 to variable "User::CUSTOMER_ID" cannot be applied.
ForEach Variable Mapping number 6 to variable "User::INCIDENT_ID" cannot be applied.
The type of the value being assigned to variable "User::CUSTOMER_ID" differs from the
current variable type. Variables may not change type during execution. Variable types
are strict, except for variables of type Object.
The type of the value being assigned to variable "User::INCIDENT_ID" differs from
the current variable type. Variables may not change type during execution. Variable
types are strict, except for variables of type Object.
I tried isnull() to both columns but of no use, i googled alot but didnt overcome it.
Please help.

SSIS is unbeleivably fussy in this area.
When retrieving those columns, I would cast them as text e.g. NVARCHAR ( 50 ). Then the Variables used in the For Each Loop Container can use Data Type = String.

Related

Handle both Type cast and Condition for Default in Derived Column

I have created an SSIS package where two columns of type varchar(1) have to be mapped to columns of Integer. I have this working using a Derived Column and giving both fields a type cast of (DT_I4). However, I discovered in the complete data set there are records with no value in these two fields and so I have to Type Cast AND add a condition in expression to default to "0" if null.
So far I have tried the following but are not valid
(IsNull[Notes Taken])?(DT_I4)"0":[Notes Taken]
(DT_I4)(IsNull[Notes Taken])?"0":[Notes Taken]
How do I create this expression properly
The most simple solution is to use REPLACENULL function like:
REPLACENULL([Notes Taken], "0")
And then - cast it to DT_I4. This function replaces the logic you are devising with conditional operator.
Your both formulas have errors. The most prominent - ISNULL is a function and needs parenthesis around its arguments, ISNULL([Notes Taken]), brackets only define a dataflow column. See MS Docs.
Then, your first expression
(IsNull[Notes Taken])?(DT_I4)"0":[Notes Taken]
Possibly the field [Notes Taken] is not matching data type of the DT_I4 which is the datatype of the first argument of ? : operator.
Your second expression
(DT_I4)(IsNull[Notes Taken])?"0":[Notes Taken]
Applies the data cast to the logical function ISNULL, not to the complete expression. You should put the parenthesis around the complete ? : operator like:
(DT_I4)(IsNull([Notes Taken])?"0":[Notes Taken])

Reading negative numbers in a column

I'm using SSIS to separate good data from unusable date. In order to do that I used derived columns, script task and conditional split where I assigned certain conditions. One of the conditions I need to apply is that none of the numbers in one column cannot be negative. I'm guessing that the best way to solve this would be using conditional split, but I cannot get it to work. I'm new to SSIS, so any help would be appreciated.
You'd have an Expression like
[MyCaseSensitiveColumnName] < 0
and then name the output path something like BadData_NegativeValue
From the comments
that is what I did before, but I'm getting an error saying that The data types "DT_WSTR" and "DT_I4" are incompatible for binary operator ">"
That error message indicates that you are attempting to compare a unicode string (DT_WSTR) and an integer (DT_I4) and that the expression language does not allow it.
To resolve this type incompatibility, you would need to first convert the value of MyCaseSensitiveColumnName from DT_WSTR to an integer.
I'd likely add a Derived Column Component to my data flow and create a new column called MyCaseSensitiveColumnNameAsInteger with an expression like
(DT_I4) [MyCaseSensitiveColumnName]
Now, that may be perilous depending on the quality of your source data. I don't know why you are pulling numeric data in as a string. If there could be non whole numbers in the data set, then we will need to check before making the cast. If there are NULLs in that dataset, those too may cause issues.
That would result in our conditional split check becoming
[MyCaseSensitiveColumnNameAsInteger] < 0

Evaluate int Variable value in Decimal in expression

I have a scenario in SSIS where I am using #BadRecordCount in rowcount transformation to count bad records and #TotalRecordCount in rowcount transformation to count total records. I need to calculate ErrorPercentage. To do this I declared another variable #ErrorPercentage and used expression - #[User::RowCountBad] *100 / #[User::TotalRecordsCount].
The expression is evaluating fine but doesn't give decimal value.
I tried changing my variable datatype to double but it is still evaluating it as integer.
I tried changing variable value to string the it throwing an error saying "*" is not allowed in specified datatype which means I cant multiply in expression.
Finally, I tried changing #BadRecordCount and #TotalRecordCount variables datatype to double along with #ErrorPercentage. Now, it is evaluating with decimal which is what I want, but when I run the package, it fails saying change #BadRecordCount and TotalRecordCount to INT as those are being used by rowcount transformation.
I want for example:
#[User::RowCountBad] =10000 and #[User::TotalRecordsCount] = 143000 then as the calculation it is giving me 6.993006993006993.
as per the expression above it is giving me only 6 but I need 6.99(up to 2 decimal).
Any Help is appreciated!
SSIS Expressions are so painful - no implicit conversions.
I would try something like this:
(DT_NUMERIC,10,2)#[User::RowCountBad] * (DT_NUMERIC,10,2)100 / (DT_NUMERIC,10,2)#[User::TotalRecordsCount]

I want to extract the parameters of a url in mysql

I have in my database a column with the parameters value of an url. I want with an sql query to put those parameters in different columns. I give an example:
I have now a column named parameters with for example this value: pOrgNum=j11000&pLanguage=nl&source=homepage
now I want three columns: pOrgnum | pLanguage | source with the values of my parameters.
The problem is that I don't know the order of my parameters or the length of it, so I can't use for example substring(parameters,9,6) to extract the parameter pOrgnum. can someone help me please?
There's a MySQL UDF that you can use to do exactly this, which also handles decoding the params and handles most character encodings, etc.
https://github.com/StirlingMarketingGroup/mysql-get-url-param
Examples
select`get_url_param`('https://www.youtube.com/watch?v=KDszSrddGBc','v');
-- "KDszSrddGBc"
select`get_url_param`('watch?v=KDszSrddGBc','v');
-- "KDszSrddGBc"
select`get_url_param`('watch?v=KDszSrddGBc','x');
-- null
select`get_url_param`('https://www.google.com/search?q=cgo+uint32+to+pointer&rlz=1C1CHBF_enUS767US767&oq=cgo+uint32+to+pointer&aqs=chrome..69i57.12106j0j7&sourceid=chrome&ie=UTF-8','q');
-- "cgo uint32 to pointer"
select`get_url_param`('/search?q=Na%C3%AFvet%C3%A9&oq=Na%C3%AFvet%C3%A9','q');
-- "Naïveté"
Disclaimer, I am the author.
I achieved this by taking the right of the string after the search parameter, then the left of the resulting string before the first &.
This handles
if the parameter was the last in the url (so no "&" follows it)
if the parameter does not exist (returns blank)
varying lengths of the search string (provided you replace "utm_medium" everywhere)
This finds the value of "utm_medium" in a parameter named url:
IF(locate("utm_medium", url)=0, '', LEFT(RIGHT(url,length(url)-locate("utm_medium",url)-length("utm_medium")),IF(locate("&",RIGHT(url,length(url)-locate("utm_medium",url)-length("utm_medium")))=0,length(RIGHT(url,length(url)-locate("utm_medium",url)-length("utm_medium")+1)),locate("&",RIGHT(url,length(url)-locate("utm_medium",url)-length("utm_medium"))))-1)) utm_medium
To use, find and replace url with your field name, and utm_medium with your url parameter.
May be inefficient, but gets the job done, and couldn't find an easy answer elsewhere
Its code work in mysql:
SELECT substring_index(URL_FIELD,'\',-1) FROM DemoTable;

Query related to set statement

what is the meaning of the S %%G=A(%%I) statement?
The statement S %%G=A(%%I) is not a valid statement in Standard MUMPS.
A related statement S %G=A(%I) is a valid statement in Standard MUMPS.
It is possible that an extension of Standard MUMPS might define a meaning for the first statement, but it isn't guaranteed to work on any system other than that implementation.
It is possible that the statement makes sense in EsiObjects or Intersystems Cache Object Script.
The related statement S %G=A(%I) means:
Command -> SET (Asssign a value to a variable)
left-hand side of SET -> %G simple temporary variable named %G accessible only from the current MUMPS job. This variable does not have to be defined, and if it is defined, any value associated with the local variable %G will be erased by the incoming value of the right hand side of the SET. (unless an error occurs)
right-hand side of SET -> A(%I) The current value of the simple temporary variable named %I which accessible only from the current MUMPS job is used as an index (or subscript) into the simple temporary array variable named A which is also accessible only from the current MUMPS job. Both %I and A at that array position must be defined.
Result of Command. The value of the local variable %I is used as an index into the local
variable A, retrieving the value at that array location. The value at that array location is then copied into the local variable %G.