I'm working on setting up a report in SSRS. Our report is somewhat flexible, and I'm looking to dynamically select an image for a cover page based on a parameter.
Here's what I have:
In our Reports db I have an image table set up. To keep things simple, lets just say I have three columns:
ImageName, ImageType, and Image.
Name and type are both varchar while ImageType is varbinary. I've uploaded the images we plan on using as well as their names and associated types to the table.
In my report I have a Data Source and a Dataset for bringing in the above table and columns.
I also have a parameter called "ImageName." I've set this parameter up to use "Image" (from the table described above) as its value field and the label field is set up for "ImageName."
On the report itself I have an image ... control? Report element? Not sure what to call it, but I've set up an image. The image source is set to "Database" and the MIME type uses the lookup function to pull the appropriate image type from the Dataset based on the Parameters!ImageName.Label argument - and that part works a treat - I'm returning the proper MIME type each time.
What doesn't work, and I would expect should work, is setting the image itself. For the "Use this field" field under "Select the image source:" I've tried both =Parameters!ImageName.Value with no success as well as a lookup based on the ImageName.Label from the images Dataset. Neither seem to work.
When I try using the parameter value, I'm getting the error
[rsInvalidDatabaseImageProperty] The value of the ImageData property
for the image 'ImageControlName' is "=Parameters!ImageName.Value",
which is not a valid ImageData.
I get essentially the same error message from the lookup method, it just swaps the lookup code for the Parameters!ImageName code above.
If I attempt to check the type returned by the lookup above I simply get an error. For the parameter if I check the type I get System.String so I decided to print that out and apparently the value of Parameters!ImageName.Value is System.Byte[] for some reason.
I can get an image to display using the First() function, but I need to be able to select the image. I'm guessing I may have to filter. First() has a return type of System.Byte[], which seems reasonable. I just don't understand why my parameter is returning the type of the image data column as a string rather than the data from the image column itself.
So how do I get this working? Is filtering my Dataset my only option? Or is there a way to get the parameter working or to get some function that will allow me to select the appropriate image?
Reason for your error is because of the data types returned by Parameters vs First.
For the Parameters data type returned is of type text and which is not valid image data type hence the error.
For First function it returns the data type based on type of expression and it returns the right type of data type for image and displays the image.
Per Microsoft Parameter Data Type:
A report parameter must be one of the following data types:
Boolean. The user selects True or False from a radio button.
DateTime. The user selects a date from a calendar control.
Integer. The user types values in a text box.
Float. The user types values in a text box.
Text. The user types values in a text box.
When available values are defined for a parameter, the user chooses
values from a drop-down list, even when the data type is DateTime.
Per Microsoft First function data type:
Return Type
Determined by the type of expression.
You are correct to get the right image you need to filter the dataset.
Create dataset which gives ImageName, ImageType, and Image.
Based on image parameter filter the dataset on ImageName.
Now use the following expression to get the correct image data.
=Fields!Image.Value
Related
I am passing a unique ID as parameter in SSRS report. In the source table, unique id does not contain dashed. However, the user may insert Unique ID including dashes "-" and in some cases without dashes. Is there a way that we could remove dashes from the parameter.
For example, unique id 3120-20268-8 is stored in table as 3120202688. How I could retrieve if user pass multiple values with or without dashes in the SSRS Report.
When is used below query, it gives record against single value only. However, gives error when more than one values are provided.
select * from Table
where Unique_ID in (REPLACE(#Unique_ID,'-',''))
For more than 1 values, it gives errors mentioned below:
The replace function requires 3 argument(s).
Query execution failed for dataset 'ATL_List'.
Thanks
One of the simplest mechanisms for this is to create an expression based parameter to hold the sanitised input. This parameter would be hidden so the user is not aware of it, but the rest of the usage of the parameter is the same.
NOTE: You could do something similar with a query based default value, but this case is easier to do via a simple expression
Single Value Parameter
Create a new parameter:
set it to hidden
Set the default value expression:
=Str(Parameters!inputID.Value).Replace("-","")
Multi-Value Parameter
This is only slightly trickier, in the expression we can join the selected values together into a CSV string, then process that value and then split it back:
Set the parameter to multi-value, but still hidden:
Set the default value expression:
=Join(Parameters!inputID.Value,",").Replace("-","").Split(",")
Without going to detailed, if we made the sanitised parameter temporarily visible, just to demonstrate the conversion, it should look like this:
The parameter MUST be hidden!
NOTE: DO NOT make your sanitised parameter visible as in the above screenshot in your deployed report! Doing so will mean that it will not pickup changes made to the input value after it has rendered the first time.
remember that we have exploited the default value, we haven't arbitrarily defined en expression to always execute.
The output when the parameter is hidden is calculated when the report is rendered, it's just harder to visualise the behavior in this static post:
In your DataSet query you would just use the sanitised parameter:
SELECT * FROM Table WHERE Unique_ID IN (#sanitisedMultiValue)
You should be able to use the replace function in your report to format the parameter value after it has been entered, something like the below
replace(Fields!Paramater.Value,"-","")=FieldinYourTable
I'm creating a single SSRS report that is composed of data drawn from different Datasets. What I'm wanting to do is have a drop down menu where the user selects the dataset they wish and have the appropriate table turn on and show them the dataset information.
Right now I'm testing with two tables and in there Visibility property I have the following expression:
=IIf(Parameters!AppSelection.Value = "STRAW", false, true)
The other table has the exact same line in the same place but with a different value between the quotes.
With my parameter, I created a new one and called it AppSelection and gave it 2 Available Values that matched the words between the quotes in my above expression. The data type for my parameter is Text and the Value of the each Available Value is left at null.
When I preview my report and select the different values in the parameter, nothing happens. What is it I'm doing wrong?
Change the null in the available values to your text, ie STRAW.
You may find that the tables show the other way round from expected, switch the true and false.
How can I limit the number of characters a user can type for a parameter in SSRS?
For example, if the Data Type is set to TEXT, how to limit the user to type only 6 characters after Default value of "CL/" OR limit to total of 9 characters.
Unfortunately you can't perform validation as people write values, you can only handle them when the report is run. You can however use Code behind the report to perform some validation on your Parameters at run-time. Based on the result of this you can then either display the required data to instead return an error message.
To insert some code behind you right click the area around the report, Choose Report Properties, then Code.
Enter something like this into the code panel
Function Validate(param) as Boolean
If len(cstr(param)) <= 9 Then
Return"True"
Else
Return "False"
End if
End Function
You can then refer to the result of this from a text box that displays an error as follows
Right click the text box and set the visibility to be
=iif(Code.Validate(Parameters!myInput.Value) = True, True, False)
Then if you enter a string of 9 or fewer characters you will get an error that you can use to inform the user of the proper format of your desired input string.
Instead of just making text boxes visible/invisible, you could also apply this to rectangles that store your report information. Also, you can use visual basic coding to alter the Code behind to perform more complicated parameter validation to check for you "CLI" string for example.
I hope this helps, let me know if you require further help.
Using SSRS 2012
I have a multivalue parameter in a report and I would like to make it the source of a table. Is there a way to accomplish this? I'm coming to the conclusion that one cannot make the data source of a table anything except a dataset.
I tried to make the multivalued dataset (source of parameter) filtered by parameter but that gives a forward reference error (makes sense).
I am now trying to set the visibility property on the table's single text box like this, so it will only make the values visible that are one of the chosen parameter values:
=IIF(Fields!MODALITY.Value = Join(Parameters!Modalities.Value,","),True,False)
but they are all shown (alway true?). Any ideas on how to show a list of the values picked from a multi valued parameter in the report as a table (not just a delimited string in a text box)?
The data source of a table will always be a dataset, but you can use the parameters in a dataset. Something like
select * from dbo.split3(#parameter)
where split3 is a csv to table function, like one found on http://blogs.msdn.com/b/amitjet/archive/2009/12/11/sql-server-comma-separated-string-to-table.aspx
I found an expression that works for changing visibility so that my table shows just the elements in the multivalue parameter that were selected. Perhaps there's an easier way.
=IIF(Instr(","+Join(Parameters!Modalities.Value,",")+",",","+Fields!MODALITY.Value+",") <> 0,False,True)
I'm new to SSRS. But I thought I had been given a simple task for my 1st request. I have a SSRS PO Report Form provided by our ERP software vendor. I only need to move the fields around to satisfy our users. I move a field from the middle of the page to an area near the top. With no other changes but when I try to run the report I get this error:
The Value expression for the text box ‘TextBox1’ refers directly to the field ‘PrintAs’ without specifying a dataset aggregate. When the report contains multiple datasets, field references outside of a data region must be contained within aggregate functions which specify a dataset scope.
I have 4 datasets in this report. They were there originally and have not been modified. To move the fields I am simply clicking on them till I get the 4 pointed arrow and dragging the field to the top of the report. Is there something under the covers that I'm missing? That needs to be changed when the field position is changed?
The object that textbox1 existed in was specifically linked to a dataset that contained the field PrintAs. I'm assuming it was a rectangle or table. You can only move textbox1 within the area of that rectangle or table or else you will see that error. If you move it outside of the bounds of that rectangle or table then you must use the LookUp function or an aggregate function in order to reference the field and get the correct value returned. What is happening in regards to the error is that the report is trying to return all the PrintAs Fields instead of just one which is causing SSRS to fail.
Is the PrintAs field exactly the same for every row in the dataset. If so you can you use this in textbox1 expression: First("Fields!PrintAs.Value,"*Dataset name*") and move the textbox anywhere you'd like. If the field is not the same you will need to use the Lookup function in the textbox to get the correct value
MSDN Lookup