Semi Urgent - Reporting Services 2005 - pass multi-value parameter to function in code behind

Posted on 2007-07-20
Last Modified: 2008-04-29
In reporting services 2005, how would I  call a function in the code behind, and successfully pass a multivalue parameter?
If i have a parameter defined for state that is multi-value, and i want to do something like this the command text window:


where the parameter "StateParameter" is a multi-value dropdown...and then in the code window have something like this:

 Public Shared Function BuildSQLQuery(ByVal strState as string) As String
        Dim sql As String = ""
        sql = " SELECT  * from SOME_TABLE WHERE state_id IN " + strState
        BuildSQLQuery = sql
End Function

When I set the state parameter to multivalue, i get a generic error - when i un-check multivalue, it passed the value to the function just fine....any ideas?
Question by:friskyweasel
    LVL 21

    Accepted Solution

    That's the syntax how to extract a list of values from a mutli-value parameter:

    =Join( Parameters!MyParam.Value, ", " )

    You may want to modify your query as well:

    "... WHERE state_id IN (" & strState & ")"

    As you're using VB.NET syntax, it's better use & to concatinate rather than +

    Why would you do this kind of thing though? I mean create a sql query in the embedded function? You can have this kind of query in your dataset and pass a multi-valued parameter EASILY there, just like that:

    SELECT  * from SOME_TABLE WHERE state_id IN ( @MyParam )

    LVL 21

    Expert Comment

    Just tested multi-value params, as in terms of passing values to your function, this syntax should work fine:

    =Code.BuildSQLQuery( Join( Parameters!StateParameter.Value, ", " ))

    Whether or not it's going to be a working SQL query ;) - is a different matter.



    Author Comment

    thanks a lot Yurich - As far as the functions in the code behind, in some of the past reports I worked on we had the need for somewhat more detailed logic...which the code behind allowed us to use (case statements, for loops, etc...) - We just continued to do it this same way on the current reports as well I guess, in case the need for more detailed programming functionality arose again. I agree it's not the most elegant solution though - In the mean time I actually did it the way you suggested in your first post ("WHERE state_id IN ( @MyParam )").
    But it's nice to know I can use the JOIN() functionality in case I need to go back to using a function in the code behind. Once, again - thanks for the perfect answer and the good tips.
    LVL 21

    Expert Comment

    My pleasure :)

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    SSRS  integration 5 71
    Access table relationships 4 37
    SQL - sum months, quarter, YTD 9 70
    Another way of doing this SQL 8 32
    I recently went through setting up a JasperReports Server using the AWS EC2 instance, and this article will cover some basic administration tasks I had to perform.
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now