change image in report builder using iif function - sql-server

I'm working with sql server report builder and I'm trying to change the value of an image according to a chosen date from a parameter.
I've selected external as source and in the expression window I have something like this:
=iif(Parameters!Date.Value <> 11.04.2013, "http://rack.0.mshcdn.com/media/ZgkyMDEyLzEyLzA0L2I1L3doZXJlZG9nb29nLmJoTi5qcGcKcAl0aHVtYgk5NTB4NTM0IwplCWpwZw/4931e287/304/where-do-google-doodles-come-from--ff2932470c.jpg", " ")
but I receive the following message:
Argument not specified for parameter 'TruePart' of 'Public Function IIf(Expression As Boolean, TruePart As Object, FalsePart As Object) As Object'.
I'm pretty new to work with the report builder, so please someone help me find out the solution.

I pasted your expression into a sample report set up with a parameter Date, data type Date/Time, and got the same error when using the expression.
I resolved this by changing the data being compared to the parameter in the expression into a string that can readily be converted to a date, so from 11.04.2013 to "11-Apr-2013":
=iif(Parameters!Date.Value <> "11-Apr-2013", "http://rack.0.mshcdn.com/media/ZgkyMDEyLzEyLzA0L2I1L3doZXJlZG9nb29nLmJoTi5qcGcKcAl0aHVtYgk5NTB4NTM0IwplCWpwZw/4931e287/304/where-do-google-doodles-come-from--ff2932470c.jpg", " ")
This stopped the error occurring for me and worked as expected when I selected different dates; i.e. the URL on all dates except 11-Apr-2013.

Related

SQL Server 2012 assembly execution failure - System.NullReferenceException: Object reference not set to an instance of an object

I am trying to execute a UDF which uses a CLR assembly. Each time I try to run it I get the below error:
Msg 6522, Level 16, State 1, Line 45
A .NET Framework error occurred during execution of user-defined routine or aggregate "Geocode":
System.NullReferenceException: Object reference not set to an instance of an object.
at ProSpatial.UserDefinedFunctions.GeocodeUDF(SqlString countryRegion, SqlString adminDistrict, SqlString locality, SqlString postalCode, SqlString addressLine)
It is a geocoding assembly, which is based on the below blog:
https://alastaira.wordpress.com/2012/05/04/geocoding-in-sql-server-with-the-bing-maps-locations-api/
Is there anything I can do to fix it? It was working fine, but just stopped working recently. I changed the Bing Maps key to a new one, but that hasn't resolved the issue. Anyone have any ideas?
Cheers
Edit: I entered a formatted URL into Chrome, to see if I can get the error. I entered the below URL format:
http://dev.virtualearth.net/REST/v1/Locations?countryRegion={0}&adminDistrict={1}&locality={2}&postalCode={3}&addressLine={4}&key={5}&output=xml
All I did was to replace items 0 to 5 with their respective entries. I left the curly brackets in there, and then also tried it without the curly brackets. Without the curly brackets, the URL returned a result with no issues.
In the browser, I am getting geocoded results, but not in SQL any more
Just worked it out. One of the address fields that was being geocoded was null in the database, and the API did not like that. So I removed that from the geocoding list
Looking at the code in that blog, if you are passing in a NULL, then it's not the API that's throwing the error. The error is happening because NULL values are not being handled when the method is first called. The code just casts the SqlString input parameters to string without first checking to see if there is a value in the SqlString variable. SqlString is very similar to a nullable string.
Fortunately, it is rather easy to adjust the code to properly handle NULL values in the input parameters. Starting with a redacted snippet of the original code below, I will show how to do this for one parameter and you can repeat that modification for the others (well, the ones that might actually be NULL in the DB; no need to do this for parameters that are guaranteed to be there due to being in a NOT NULL column).
public static SqlGeography GeocodeUDF(
SqlString countryRegion,
SqlString adminDistrict,
SqlString locality,
SqlString postalCode,
SqlString addressLine
)
{
...
string localAdminDistrict = string.Empty;
if (!adminDistrict.IsNull)
{
localAdminDistrict = adminDistrict.Value;
}
// Attempt to geocode the requested address
try
{
geocodeResponse = Geocode(
(string)countryRegion,
localAdminDistrict,
(string)locality,
(string)postalCode,
(string)addressLine
);
}
All I did was:
Added a local variable for localAdminDistrict, defaulted to an empty string.
Added an if block to set localAdminDistrict if adminDistrict is not null.
Updated the call to Geocode() to use localAdminDistrict instead of (string)adminDistrict.
This should work as long as the Bing Maps API is ok with an empty value for adminDistrict (i.e. ...&adminDistrict=&locality=... ), as opposed to adminDistrict not being present in the GET request (which is easy enough, it just requires an additional modification).
ALSO: As long as you are going to be in there updating the code, you really should move the calls to the Close() and Dispose() methods into a finally block for that try / catch.
For more info on working with SQLCLR in general, please visit: SQLCLR Info

Report column is showing #Error when using Subscriptions

As titled, when using SSRS 2017 subscriptions to generate a report, a column with expression is showing #Error. However, when I try to run manual in web and in the report builder, it can be shown.
The Expression is:
=Code.Decode(Fields!Comments.Value)
The function is:
Function Decode(ByVal EncodedString AS String) AS String
Return System.Web.HttpUtility.HTMLDecode(EncodedString)
End Function
Any suggestion or help will be welcome.
I resolve the problem by myself. Use the following method instead
Function Decode(ByVal EncodedString AS String) AS String
Return System.Net.WebUtility.HtmlDecode(EncodedString)
End Function

Adding Strike-through effect in SSRS report textbox

I am working on a SSRS report.
Business Requirement: One of the business req is that if the statusId which we get back comes as 3 then add a strikethrough line over the textbox. This textbox is outside the dataregion.
Here is what I have gotten so far but I am getting errors.
I right clicked on the textbox -> went to Properties. -> went to Font. ->
clicked Expression button from effects and applied this syntax in
there:
=IIf(sum(Fields!RequestStatusId.Value, "GetRequestById") = 3 "Default", "LineThrough")
Below is the error that I am getting:
Severity Code Description Project File Line Suppression State
Error [rsCompilerErrorInExpression] The TextDecoration expression for the textrun ‘Textbox158.Paragraphs[0].TextRuns[0]’ contains an error: [BC30455] Argument not specified for parameter 'TruePart' of 'Public Function IIf(Expression As Boolean, TruePart As Object, FalsePart As Object) As Object'.
What am I doing wrong ? Can someone help me with my expression which I applied. Thanks!
Missing a comma after the 3, assuming that is exactly the expression being used.
=IIf(sum(Fields!RequestStatusId.Value, "GetRequestById") = 3, "Default", "LineThrough")

SSRS expression for empty parameter value returns #Error

I have a parameter in report that I recently changed it to accept NULL values. It was a required parameter before but now it is not required. Header in the report has below expression to read data from the parameter value. Ever since I modified the parameter to accept NULLvalues, it is erroring out. It shows #Error in the header. I have tried modifying the expression to display result even if the parameter is 'NULL', but nothing has worked so far. I am pretty much stuck here. Here is the expression I am using in SSRS:
=IIF(Code.MultipleValues(Parameters!ProductID.Value(0))="True"
,IIF(IsNothing(First(Fields!ProductName.Value, "ProductHeader")),""
,First(Fields!ProductName.Value, "ProductHeader")).ToString
,IIF(Len(Parameters!ProductID.Value(0)) > 0
,IIF(First(Fields!ProductName.Value, "ProductHeader") is nothing,""
,First(Fields!ProductName.Value, "ProductHeader")),"All Products Selected"))
I believe the error has to do with the VB custom code that is in the report. I am not too familar with the code so I am having trouble troubleshooting it.
VB code:
Public Function MultipleValues(ByVal str As String) As String
If str.Contains(",")
Return "True"
Else
Return "False"
End If
End Function
Any suggestion on how to handle #Error in SSRS? thanks
Replace
Code.MultipleValues(Parameters!ProductID.Value(0))="True"
with
IndexOf(Parameters!ProductID.Value(0).ToString(),",") >= 0
Instead of a function, can you just put the IsNothing check in front of the parameter ?
=IIF(Code.MultipleValues(IsNothing(Parameters!ProductID.Value(0),""))="True"

How do I format a string while using a BindingSource?

Technology: Visual Studio 2008 .NET, Winforms
bsTransactions.DataSource = Transactions.Tables[2];
bsnTransactions.BindingSource = bsTransactions;
txtTransOverrideDate.DataBindings.Add("Text", bsTransactions, "TransactionDate", true,DataSourceUpdateMode.Never, "", "MM/dd/yyyy");
Currently, I'm getting an error saying that the string wasn't a recognized DateTime string. Despite the fact that if I get the column type from
Transactions.Tables[2].Rows[0]["TransactionDate"].DataType.ToString();
returns "System.DateTime" and the actual value looks like "1/23/2010 12:00:00 AM"
I'm trying to format a string that currently looks like "1/23/2010 12:00:00 AM" to only show the date.
The catch is, there's a BindingSourceNavigator being use, so just applying the formatting to the textbox after the fact only applies to the first value, but not any others that are navigated to using the bindingNavigator.
I have a feeling that using the "bsTransactions" to applies bindings to the textbox, it's changing the datatype, hence it not being recognized as a DateTime.
txtTransOverrideDate.DataBindings.Add("Text", bsTransactions, "TransactionDate", true,DataSourceUpdateMode.Never, "", "MM/dd/yyyy");
I made changes in the original post to mimic this, but this is the answer.

Resources