Multi-value parameters in ssrs - sql-server-2008

I have a multi-value parameter. how I get one by one values from this parameter.
value=new_index and label=new_french
and want to insert these values into these labels

You can access the individually selected multi-value parameters by their index (the index is zero-based). So if you want the first selected parameter value (for example, to put it into a label), you can address it like so:
=Parameters!MyParameter.Value(0)
You could access them all using custom code:
Function DoSomething (ByVal parameter As Parameter) AS String
Dim Result As String
If parameter.IsMultiValue then
For i As integer = 0 To parameter.Count-1
Result = Result + CStr(parameter.Value(i)) + ", "
Next
Result = Left(Result, Result.Length - 2)
Else
Result = CStr(parameter.Value)
End If
Return Result
End Function
then use this expression to access the result:
=Code.DoSomething(Parameters!MyParameter)
Note that you are passing the parameter object here, not the Value property. We access the Value property in the custom code function.

Related

How to display number values with commas in form

In my Access query, I have the query using a VBA function to figure the value that goes in the query field.
In the form, if the stringval textbox has a value, then I want to compute it, but if not, it should remain empty (null).
Function GetValue(stringval, numval)
Dim result
stringval= stringval & ""
result= IIf(stringval<> "", numval* 1.5, Null)
GetValue = Int(result)
End Function
Now, I have a form that uses this query, and on the form is a textbox that displays the query value. I want the value to be formatted with commas in the numbers for easy reading. Everything I've tried so far does not show any commas.
I've tried:
used Standard for the Format > Formatfor the textbox (in properties)
putting #,###.### in the textbox Format value
putting #,##0.0## in the textbox Format value
changing Data > Text Format but it only gives me Plain Text and Rich Text - no option for numbers.
returning a double from the function
Note: if I don't use a custom VBA function, and write the formula directly into the query, then it does display commas. But when I move the formula into the function then the commas are lost.
What do I do?
[update]
I tried Gustav's solutions and since they didn't work for me, I added those as items to my "what I've tried" list above.
Also, if I look at the query in datasheet view, the number values sort alphabetically instead of by the size of the value. When I used the forumulae directly in the query instead of using functions, it sorted by the value of the number. I hope this is a clue.
Numbers carries no format. A format is applied when displayed only.
But be sure to return a Double if not Null:
Function GetValue(stringval, numval)
Dim result
If stringval & "" <> "" Then
result = Int(CDbl(numval) * 1.5)
Else
result = Null
End If
GetValue = result
End Function
Then apply your Format to the textbox
#,##0.0##
Or force a formatted string to be returned:
If stringval & "" <> "" Then
result = Format(Int(CDbl(numval) * 1.5), "#,##0.0##")
Else
result = Null
End If
and skip formatting of the textbox.
The solution is this: the function has to be declared as a double.
That allows the query's datasheet view to know it is displaying numbers - and so you can set the field's format to Standard for the comma to display. This also allows the form to know it has a number and it will display the comma there, too. I knew it had to do with double, but didn't realize before that the function needed to be declared as such.
Function GetValue(stringval, numval) as double '<----THIS!!!!
Dim result
If stringval & "" <> "" Then
result = numval * 1.5
Else
result = 0 `<--can't return null here; use nz function in control source for textbox
End If
GetValue = int(result) 'to remove decimals
End Function
The problem I was having was in some of my functions I need to return double or null, because I wanted textboxes to remain blank if they contained no data. Now, at least I know how to make the numbers generated by functions to display commas.
And here is how to deal with the fact that you can't return null as the value of a double. The function is originally from here.
Put this function in a module so it is public, and then in the control source for the textbox, instead of just putting the field value, put Zn(fieldvalue). This works like a charm (although using functions in the control source seems to have a delay on the form display). This way you can keep the underlying value as a double and still get commas to display in both the form and the query whilst keeping the field blank if necessary.
Public Function Zn(pvar)
' Return null if input is zero or ""
If IsNull(pvar) Then
Zn = Null
ElseIf IsNumeric(pvar) Then
If pvar = 0 Then
Zn = Null
Else
Zn = pvar
End If
Else
If Len(pvar) = 0 Then
Zn = Null
Else
Zn = pvar
End If
End If
End Function

MS Access: lookup values for string-based multi-value field

Here is my situation:
linked table (so I can't actually modify the column config) has a column with a comma-separated list of values. this is a text string -- not a true multi-value field.
I need to map those values to a lookup table and return a comma-separated list using the lookup values
So let's say a row has the values: A,B,C in this column. The mapping table maps: A|1, B|2, C|3. The resulting column in my query should list 1,2,3 (the mapped values).
I can add a column in my query, indicate the display control is combo box (which is what you would typically do for a multi-value field), select my row source, and bind the columns -- but only rows with a single option value will map correctly. If it has a comma-separated list, per the above example, it does not map the values. How would I go about this mapping?
To display such results, you would need a VBA function.
The code would look like:
Public Function TransComma(MyList As Variant) As String
Dim TransList As Variant
Dim Token As Variant
Dim result As String
If IsNull(MyList) = False Then
TransList = Split(MyList, ",")
For Each Token In TransList
If result <> "" Then result = result & ","
result = result & DLookup("Color", "tblColors", "ID = " & Trim(Token))
Next Token
TransComma = result
End If
End Function
The above code is to be placed in a standard code module.
Now in a form you can place a text box, and set the control source to this
=(TransComma([name of field]))
And for a report, or sql query, simply go:
Select firstName, LastName, ColorList, TransComma([ColorList)
as translated from tblCustomers
So once you build this translate function, it can be used translate the numbers to some text.

Display the non selected parameter in SSRS

In case of Multi-valued parameters,we usually use join function to display the selected values into a Text-box.But what if I wanted Show only the non selected parameters?IE If there are 10 values in the drop down list of a parameter and I selected the first 5 and wanted to display only the remaining 5 parameter instead of the first 5.What do i do?
I have created a multivalue parameter with the name Param which has had its labels and values set like so:
Label Value
====== =====
Label1 1
Label2 2
Label3 3
Label4 4
Label5 5
I then created the following code in the Report Properties --> Code menu:
'Global array objects to hold the total and selected values
Private Dim parameterList() AS string
Private Dim selectedParameters() AS string
'populates the list of all parameters using split and returns the input string
Public Function SetParameterList(nextParameter as String) AS String
parameterList = Split(nextParameter ,",")
Return nextParameter
End Function
'populates the list of selected parameters using split and returns the input string
Public Function SetSelectedParameters(delimitedParameters as String) AS String
selectedParameters = Split(delimitedParameters,",")
Return delimitedParameters
End Function
'Returns the not selected parameters
Public Function GetNotSelectedParameters() AS String
Dim notSelected As String
Dim i as Integer
Dim x as Integer
'Loop through each value in the all parameters array...
For i = 0 to parameterList.GetUpperBound(0)
'...for each one of those values check it against the selected parameters
For x = 0 to selectedParameters.GetUpperBound(0)
'Where there is a match, set the all parameters value to a string unlikely to be a genuine parameter value
IF parameterList(i) = selectedParameters(x) Then
parameterList(i) = "!*!"
End IF
Next
Next
'Join the all parameters array back into a string
notSelected = Join(parameterList, ", ")
'Remove the !*! values added earlier from the middle and the end of the string
notSelected = Replace(notSelected, "!*!, ", "")
notSelected = Replace(notSelected, ", !*!", "")
Return notSelected
End Function
To use this code I created 3 textboxes with the following expressions:
=Code.SetParameterList(Join(LookUpSet(1,1,Fields!ParamLabel.Value,"DataSet1"),","))
=Code.SetSelectedParameters(Join(Parameters!Param.Label, ","))
=Code.GetNotSelectedParameters()
Note: to hide the output of any of these textboxes, you could set the function return value to be "".
I imagine my code could be improved upon significantly, but this gets the job done and should at least point you in the right direction.
First create a multivalued parameter ("param1"), with available values ranging from 1 to 10.
Then create a query (query1), which returns the parameters from 1 to 10 filtering out the
selected values from "param1" -> where query1.col NOT IN (#param1)
Then create another multivalued parameter("param2"), set a default value (get values from a query) point to "query1" to fill in the unselected values
use a text box with the following code "=Join(Parameters!param1.Value,",")"
To make query1 you can use unions.
You will get back the values not selected,

NOT IN in SSRS TextBox

How can I write NOT IN in TextBox expression?
I must check if some field value not belong to some list of strings, and then do some work.
Example:
Iif(SomeField.Value NOT IN ('Text1', 'Text2'), DoSomething, nothing)
I wrote code like this and got error when previewing report, and error was :
Overload resolution failed because no accessible 'Iif' accepts this number of type arguments
How can I do this stuff?
Try this small piece of custom code that accepts a string array. Just paste it into the report code section of the report..
Public Shared Function ValueExists(ByVal arr() as string, checkVal as string)
Dim i As Long
For i = LBound(arr) To UBound(arr)
If arr(i) = checkVal Then
return true
Exit Function
End If
Next i
return false
End Function
Usage would involve splitting the string into an array using the Split function
like so:
=iif(Code.ValueExists(Split("Your,comma,separated,string,in,here",","),"StringYouWantToFind")
,"Your value exists"
,"your value does not exist")
You can simply write the code like this:
Iif(SomeField.Value <> 'Text1' AND Field.Value <> 'Text2' , DoSomething, nothing)
I got this one in one report:
=iif(join(Parameters!Parameter1.Value,",") like "*" & Fields!Field1.Value & "*","Color1","Color2")
This instruction helps me to determine the fill colour of a cell inside a tablix, where:
Parameter1 is a multivalue parameter.
"Join" lets me have a string with all selected values from a multivalue parameter, eg. "value1,value2,value3,value4"
Field1 is the field that contains the values filtered by Parameter1
Color1 is the color if the value of the cell is included in the selection of parameter
else Color2
works well

Populating multiple values in rdlc reporting

I am using rdlc report, i have a column in database which i want to display in the report.
vehicleDamageArea=1,2,3
In the report I need to mark the placeholders with these values.
=iif((Fields!vehicleDamageArea.Value="3"),Chr(253),Chr(168)) like this.
But as we know,it will check the whole value 1,2,3="3" not the splitted values.
Any suggestion to check by splitting the vehicleDamageArea parameter.
I made it to work as below
Public Shared Function CheckValue(ByVal InString As String,ByVal input as String) As Char
Dim output As String = String.Empty
Dim Parts() As String = InString.ToString().Split(",")
For i As Integer = 0 To Parts.Length - 1
If Parts(i) = input Then
output = Chr(0120)
Exit For
Else
output = Chr(0111)
End If
Next i
Return output
End Function
You can get the individual values using the split function in reporting services. It returns a zero-based string array, so for your example you need
=Split(First(Fields!ID.Value),",")(2)
You should make a function that accept a comma separated expression, than process this string and return a Boolean, then call this function as for boolean value.