Evaluate int Variable value in Decimal in expression - ssis

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]

Related

SSIS REPLACE Function - Derived Column

I have a variable with a value of '1617'. It is a DT_WSTR datatype currently. Sometimes I need a string, others an integer.
I am using a derived column to replace the ' values so that I can cast this value as an integer.
My replace function is not working.
REPLACE([User::schoolYear],"'","")
What am I doing wrong?
The problem with your supplied expression, is that you are not referencing the variable schoolYear. Sometimes, you can address a variable as #schoolYear but the consistent, explicit syntax I would encourage is #[User::schoolYear] That way, you can identify the namespace in case someone like me has used a custom namespace.
Your Derived Column expression then becomes
REPLACE(#[User::schoolYear],"'","")
You are having space before and after the single quote, which is causing the replace to fail.
Modify the expression as given below. I have tested it. It is working fine.
REPLACE([User::schoolYear],"'","")

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

How to change the field type of result set from SQL pass-through (SPT)?

I have a mysql table column defined as unit_price float(12,4).
If I assign a value of 0.1234, when I create a remote view with dbsetprop, I can retrieve 0.1234 with myview.unit_price.
However, when I use SQL pass-through (SPT) like this:
sqlexec(nHandle, "select * from table", "oResult")
the result of oResult.unit_price only shows 0.12.
How can I ensure that I return the correct, full value?
Not having explicitly tried, you can do some simple math forcing to create larger precision, such as adding an additional column to your query... something like...
select *, unit_price * 1.00000 as UnitPrice5 from...
This will force the field to be computed to 5 decimal position and MIGHT actually change the result column to properly handle this forced decimal capacity. Then, you would use the "UnitPrice5" column instead of "unit_price"...
Don't know if that would be a big issue for you, but once it is in VFP, you have more control too.
The length of the decimal values are defined in your FoxPro settings. Go to Tools->Options->Regional and set the Decimal Digits to a higher value.

SSRS FormatNumber Error

trying to format number (decimal), but it shows me #Error on production server:
=FormatNumber(First(Fields!SumWithMailDelivery.Value, "document"), 0)
but on developers server it works fine.
Maybe someone know, how can i resolve this?
p.s. without formatting it works on production server fine too.
As #IanPreston says, it is most likely a type conversion error. I imagine your production data has some invalid characters for that column or some Null columns that make the numeric conversion fail.
You can use the Val function to do the conversion. Val differs from other numeric conversion functions in that it won't error when the string to be converted isn't numeric - it just does the best job it can.
So try an expression like this for the Value property:
=IIF(Fields!SumWithMailDelivery.Value Is Nothing,
Nothing,
IIF(IsNumeric(Fields!SumWithMailDelivery.Value),
Val(Fields!SumWithMailDelivery.Value),
Fields!SumWithMailDelivery.Value)
)
then use N0 as the Format property to format it as numeric if possible.
This formula will:
Leave the cell as Nothing if the field is Null
Convert to numeric and use the appropriate format if possible
Otherwise just output whatever is in the field

Why does this work priority = ''-1 in Mysql

Can anyone tell me why this works in mysql?
update routing_policy set priority=''-1 where id = 1;
You're subtracting 1 from the empty string, evaluated as 0 for this purpose, therefore the result is -1. Take a look at the manual page about Type Conversion in Expression Evaluation for more about this.
Your value for priority is invalid:priority=''-1`. You're attempting to subtract a number from a string or your value is outside of the quotes (which shouldn't be an issue if you used an integer data type).