set value of variable and use it in same SSRS expression - reporting-services

In SQL server reporting services(SSRS) tablix cell, i want to write an expression as follows:-
set the value of variable and use that variable in "if" condition.
i have written following expression and its working fine, only issue is i want only "if" condition to be evaluate.
currently output is : "TrueVariable text is NA"
=Variables!myVar.SetValue("NA")
&IIf(Variables!myVar.Value="NA","Variable text is NA","Variable text is not NA")

The result you get is because you are concatenating both expressions, the assignment and the conditional.
The assignment returns "True" and the conditional "Variable text is NA" therefore the result is "TrueVariable text is NA"
if you want just the result of the conditional you can for example wrap the assignment inside an IIF, and as it always will be true, then you can do something like this
=IIF(Variables!myVar.SetValue("NA"),
(IIf(Variables!myVar.Value="NA","Variable text is NA","Variable text is not NA"), "should never get here"
)

Related

SSRS Parameter Specify Values - Expression Not Working

In SSRS, I am trying to use an expression to specify the available value for a text box parameter. I have tried several different things but my text box never gets populated with data. For the purpose of this post I have made the expression as simple as possible. Below is an example. The parameter is defined as single-value, non-blank, non-null, and visible.
Custom Code:
Public Shared Function TestFunc() as String
return "test"
End Function
Parameter Label: =Code.TestFunc()
Parameter Value: =Code.TestFunc()
In this simple example I would expect the text box parameter to have the value 'test' but this is not the case. What am I missing here? Is there a different syntax or a setting that I'm unaware of?

MS Access, Use Expression Builder to Compare Field in One Table to DLookup in Another Table

I'm trying to make a MS Access report, where I use a text box to display a field value, then have another text box indicating if the first value is higher or lower than an entry in a separate table.
The report has a record source of "Table 1", and a textbox named "txt_Value1" which displays the number in Field: "Value1". I have a second table, "Customer_Criteria" which has a field "PassValue" that I want to compare against. My expression builder statement is:
IIf([txt_Value1]<(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'")),"TRUE","FALSE")
This statement always returns false, regardless of what the correct logical result is.
I've tested it, writing:
IIf(1<(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'")),"TRUE","FALSE")
And I get the correct results. Also, if I write:
IIf([txt_Value1]< 1,"TRUE","FALSE")
I get the correct results. What am I missing to compare the textbox value vs. the Dlookup?
As I understand, both fields are numeric. Access may consider those fields as text, so for correct comparing use type conversion.
Try this:
IIf(CLng(Nz([txt_Value1],0))< _
CLng(Nz(DLookUp("[PassValue]","[Customer_Criteria]","[Customer] = 'ABC'"),0)), _
"TRUE","FALSE")
Nz required if fields may contain NULL values, in this case type conversion function will return error.

LIKE operator in SSRS row visibility expression

I have a text box within an rdl report which I want to suppress based on certain terms in my dataset (i.e. if the query returns a term which ends with the letter "L" then hide the text box).
Within the textbox properties I have set visibility expression for Hidden with the below expression:
=First(Fields!STERMS__.Value, "Job") NOT LIKE '%L'
When I run it I get the error:
"The Visibility.Hidden expression for the text box contains an error:
[BC30201] Expression expected"
It seems like a schoolboy error but I have tried various permutations on this expression with no luck. Any help would be appreciated.
SSRS expressions are funny in some ways. I think what you're looking for is:
=IIf(First(Fields!STERMS__.Value, "Job") Like "*L", True, False)
The gist is that SSRS doesn't use SQL syntax. It's VB
I think you could use the Right() function which returns a specified number of characters from the right hand side of a string.
E.g.
=Right(Fields!STERMS__.Value,1)
I guess in your case for Hidden property on the cell, the expression would look like this
=IIF(Right(First(Fields!STERMS__.Value, "Job"),1)=="L",true,false)

Check null and split value in textbox in SSRS report

I am facing very simple issue but not getting solution over it.
I have textbox in my ssrs report, I am passing value "1;prashant" or null to it. Now, if I pass value "1;prashant" to textbox then textbox should show only "prashant" and If I am passing nothing then it should be blank.
I have tried following IIF condition:
=IIF(IsNothing(FieldS!WIAPPORVER.Value),"",Split(Fields!WIAPPORVER.Value,"#")(1).ToString())
But, I above code is giving an error ["#error" shows in textbox] if I am passing blank value.
Please let me know, where I am wrong in this.
Thanks
There are probably better ways of doing this, but this is what my head came up with at the time:
=IIF(
IsNothing(Fields!WIAPPROVER.Value)
,""
,Right(Fields!WIAPPROVER.Value,Len(Fields!WIAPPROVER.Value) -InStr(Fields!WIAPPROVER.Value,";"))
)
I believe SSRS is trying to compute everything in the report at runtime, so in your case it is still trying to fetch index 1 from an array even though there is nothing in it and it crashes.
Edit: Changed parameters to Fields. I created a parameter to remake the issue at my side.
Just get the split out of the iif. Then in your iif, if field is nothing create a string that when split will return ""
=Split(IIF(IsNothing(FieldS!WIAPPORVER.Value),"#", Fields!WIAPPORVER.Value),"#")(1)
You are relying on the IIf expression short circuiting, but SSRS IIf expressions do not short circuit - the expression will try and work out Split(Fields!WIAPPORVER.Value,"#")(1).ToString() for all rows and fail when this value doesn't exist.
You can get this going by using text expressions, which don't get this error.
With test data:
And a simple table:
I have added columns with both your existing expression and a new expression:
=Right(Fields!WIAPPORVER.Value, Len(Fields!WIAPPORVER.Value) - InStr(Fields!WIAPPORVER.Value, "#"))
This new expression works for NULL values, empty strings and strings with no delimiter present:

Dealing with blank or null in ssrs

In my report, I have an expression which is used to pass a parameter to a child report parameter which is set to allow null values. The expression is :
=IIf(Parameters!Lead.Value = "False",Nothing,Fields!Paid.Value)
The above expression returns values only when Fields!Paid.Value is not blank. Therefore when Fields!Paid.Value is blank I get an error
"the value provided for the report parameter is not valid"
How do I modify my expression to parse these two conflicting issues?
What I want is to be able to return values when the Fields!Paid.Value is blank or when it is not. So at all time when the expression runs corresponding values are returned without the error stated above.
Thanks for helping out.
The first thing you do, wherever you have used the "Paid" parameter, set it to allow null value. Allow null only not blank.
The second thing about the expression, use something like this,
=IIF(Parameters!Lead.Value "FALSE", Nothing, IIF(IsNothing(Fields!Paid.Value),0,Fields!Paid.Value)