=Lookup(Fields!ID.Value+Fields!Name.Value+Fields!Age.Value,Fields!ID.Value+Fields!Name.Value+Fields!Age.Value,Fields!Amount.Value,"Table2")
=Lookup(Fields!ID.Value &Fields!Name.Value &Fields!Age.Value,Fields!ID.Value &Fields!Name.Value &Fields!Age.Value,Fields!Amount.Value,"Table2")
While using above two expressions in ssrs its displaying error like :
An Unexpected error occurred while compiling expression. Native
compiler returns value: Operator + is not defined for type 'object'
and
'Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.Field'.
An Unexpected error occurred while compiling expression. Native
compiler returns value: Operator & is not defined for type 'object'
and
'Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.Field'.
Please provide a solution to run lookup with multiple columns.
Thanks You.
The first step I would take would be to cast every field value as a string. To do that addCStr(<Value>) around every field value. My assumption is that SSRS doesn’t like concatenating numbers and strings.
Related
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])
I'm having a little trouble with an SSIS expression where, in a Derived Column Transformation Data Flow Task, I am attempting to grab a 6 character substring from a string input, casting the derived columns value to NULL if it doesn't exist. This is the code I am using, with line breaks and indentation added for readability:
KeyValueLength == -2 ?
NULL(DT_STR,6,65001) :
(
KeyValueLength == -1 ?
(DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999)) :
(DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength)
)
(For reference, when KeyValueLength is -2 the key value is not found, when it is -1 then it is found at the end of StringInput, any other number and it is found in the middle of StringInput. This code works for other key values I'm getting that are casting to DT_I4 and DT_DECIMAL)
Individually, the following three expressions do not generate an error:
NULL(DT_STR,6,65001)
(DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999))
(DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength)
But when put together in that nested conditional above, I get the following error when trying to save the window:
For operands of the conditional operator, the data type DT_STR is
supported only for input columns and cast operations. The expression
"KeyValueLength == -2 ? NULL(DT_STR,6,65001) : (KeyValueLength == -1 ?
(DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999)) :
(DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength))"
has a DT_STR operand that is not an input column or the result of a
cast, and cannot be used with the conditional operation. To perform
this operation, the operand needs to be explicitly cast with a cast
operator.
I'm having a little trouble figuring out exactly what the issue is here. That error message suggests it's to do with the use of conditionals, but I'm not seeing the problem.
So, in the infinite wisdom of Microsoft, this is null as a DT_STR and perfectly valid as a direct value assignment:
NULL(DT_STR,6,65001)
But if you want to assign that value in a conditional where all eventual conditions must be the same type you have to do this:
(DT_STR,6,65001)NULL(DT_STR,6,65001)
The same does not apply for other types, where something like NULL(DT_I4) is valid irrespective of whether it is directly assigned or assigned via condition. SMH
I am using sqlalchemy on a postgres database, and I'm trying to do arithmetic in a SELECT on two JSON fields which represent floats. However, I have not figured out how to make this work.
Assume I have properly defined a table called transactions which contains a JSON column called cost_data, and assume that this JSON structure contains two attributes called cost and subtotal which represent float values.
In a SELECT statement, I generate the sum of those two fields as follows:
(cast(transactions.c.cost_data['subtotal'], sqlalchemy.Float) + cast(transactions.c.cost_data['cost'], sqlalchemy.Float)).label('total_cost')
This generates the following SQL fragment ...
CAST((transactions.cost_data -> %(cost_data_6)s) AS FLOAT) + CAST((transactions.cost_data -> %(cost_data_7)s) AS FLOAT) AS total_cost
(where cost_data_6 and cost_data_7 get set to subtotal and cost, respectively).
However, I get the following error:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) cannot cast type json to double precision
If I remove the casting and do it as follows, it also fails ...
(transactions.c.cost_data['subtotal'] + transactions.c.cost_data['cost']).label('total_cost')
I get this error ...
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) operator does not exist: json || json
LINE 9: ... (transactions.cost_data -> 'subtotal') || (transa...
^
Clearly, this is because the fields come in as strings, and the "+" operator gets interpreted as string concatenation.
Also, if I use the Python float operator, it also fails ...
(float(transactions.c.cost_data['subtotal']) + float(transactions.c.cost_data['cost'])).label('total_cost')
The python interpreter doesn't even execute the code, and it gives this error:
TypeError: float() argument must be a string or a number, not 'BinaryExpression'
So how can I perform the addition of those two fields using sqlalchemy?
PS: the following is a typical cost_data column value ...
{"cost":3.99,"subtotal":12.34}
OK. I finally figured it out. I have to pass each reference through the astext operator before applying cast, as follows ...
(transactions.c.cost_data['subtotal'].astext.cast(sqlalchemy.Float) + transactions.c.cost_data['cost'].astext.cast(sqlalchemy.Float)).label('total_cost')
The accepted answer works when only using SQLAlchemy with PostgreSQL, but it is not portable to other databases that have JSON types.
If you want to write code that is portable between PostgreSQL, MySQL, and SQLite, then you should cast a JSON column using one of the column's as_*() methods.
OP's answer would look like:
transactions.c.cost_data['subtotal'].as_float()
The methods .as_float(), .as_string(), .as_boolean(), and .as_integer() are available on SQLAlchemy JSON columns since SQLAlchemy version 1.3.11. More documentation here.
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
I am using Execute Process task in SSIS 2008 R2. I have a variable idVar which is of data type Int32. I need to pass this variable to property Arguments of the task so the process executable can take this variable as argument. I use expression to assign #idVar to Arguments.
Now the system says I need to convert Int to String so I used the following expression in the expression builder
(DT_STR, 10, 1252) #[User::IdVar]
It gives the following error:
Expression cannot be evaluated.
Additional information:
The expression "(DT_STR, 10, 1252) #[User:IdVar]" has a result type of "DT_STR",
which cannot be converted to a supported type.
(Microsoft.DataTransformationServices.Controls)
What is the correct way to type cast the number to string?
Cause of the issue:
Arguments property in Execute Process Task available on the Control Flow tab is expecting a value of data type DT_WSTR and not DT_STR.
SSIS 2008 R2 package illustrating the issue and fix:
Create an SSIS package in Business Intelligence Development Studio (BIDS) 2008 R2 and name it as SO_13177007.dtsx. Create a package variable with the following information.
Name Scope Data Type Value
------ ------------ ---------- -----
IdVar SO_13177007 Int32 123
Drag and drop an Execute Process Task onto the Control Flow tab and name it as Pass arguments
Double-click the Execute Process Task to open the Execute Process Task Editor. Click Expressions page and then click the Ellipsis button against the Expressions property to view the Property Expression Editor.
On the Property Expression Editor, select the property Arguments and click the Ellipsis button against the property to open the Expression Builder.
On the Expression Builder, enter the following expression and click Evaluate Expression. This expression tries to convert the integer value in the variable IdVar to string data type.
(DT_STR, 10, 1252) #[User::IdVar]
Clicking Evaluate Expression will display the following error message because the Arguments property on Execute Process Task expects a value of data type DT_WSTR.
To fix the issue, update the expression as shown below to convert the integer value to data type DT_WSTR. Clicking Evaluate Expression will display the value in the Evaluated value text area.
(DT_WSTR, 10) #[User::IdVar]
References:
To understand the differences between the data types DT_STR and DT_WSTR in SSIS, read the documentation Integration Services Data Types on MSDN. Here are the quotes from the documentation about these two string data types.
DT_STR
A null-terminated ANSI/MBCS character string with a maximum length of 8000 characters. (If a column value contains additional null terminators, the string will be truncated at the occurrence of the first null.)
DT_WSTR
A null-terminated Unicode character string with a maximum length of 4000 characters. (If a column value contains additional null terminators, the string will be truncated at the occurrence of the first null.)
Expression:
"Total Count: " + (DT_WSTR, 11)#[User::int32Value]
For reference, Int 32's range is (-2,147,483,648 to 2,147,483,647). Including the - sign for negatives, that makes up to 11 characters.
Expression:
"Total Count: " + (DT_WSTR, 5)#[User::Cnt]