Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Reporting 2008; Check if an Array Contains a String

In SQL Reporting 2008 how can I determine if an Array Contains a String?

Example, I wish the following to return "1":

IIf(Split("a,b,c", ",").CONTAINS("a"), "1", "0")

What may be used in replace of the above CONTAINS function? Is it impossible? This value'd be the FilterExpression for my table. Its purpose is to decide what to show and what to hide.

like image 583
JonathanWolfson Avatar asked Jul 26 '11 15:07

JonathanWolfson


2 Answers

If you are looking for an answer only in an expression, I am not positive. However, you can write .Net methods and call them just like expressions from a custom dll or a "code" section of the report. If you use built-in code, you can do something like the following:

http://www.vbforums.com/showthread.php?t=558440

Creating inline code or referencing an assembly in SSRS:

http://bryantlikes.com/pages/824.aspx

UPDATE: Example to get your delimited values from your concatenated string:

http://www.dotnetperls.com/split-vbnet

UPDATE:

Here is a function you can use. You put it in the code section of the report:

Public Function Contains(ByVal ItemToCheck As String, ByVal CommaValuesList As String, ByVal delimeter As Char) As Boolean
    Dim commaValues() As String = Split(CommaValuesList, delimeter, -1, CompareMethod.Text)

    For Each commavalue As String In commaValues
        If ItemToCheck.ToLower.Trim = commavalue.ToLower.Trim Then
            Return True
        End If
    Next

    Return False
End Function

Use the following syntax to reference it:

=code.Contains(param1,param2,param3)
like image 92
Frank Pearson Avatar answered Oct 04 '22 03:10

Frank Pearson


Let's use MyLettersParameter as a multiselect parameter. To determine if it contains "a" use:

=Array.IndexOf(Parameters!MyLettersParameter.Value, "a") > -1

The above code returns true or false. To return "1" use:

=IIf(Array.IndexOf(Parameters!MyLettersParameter.Value, "a") > -1, "1", "0")
like image 27
Homer Avatar answered Oct 04 '22 03:10

Homer