How to create a multi-select parameter with a uniqueidentifier?

后端 未结 2 803
星月不相逢
星月不相逢 2020-12-11 11:17

I am developing an SSRS 2008 R2 RDL file. Now, I am trying to add a report parameter which should be a multi-select. Previously I have worked with multi-select parameters

相关标签:
2条回答
  • 2020-12-11 12:10

    But the line that causes this error is:

    AND (@IncidentType is NULL OR event_definition_rv.event_definition_id in (SELECT Names FROM #incident_types))
    

    Since @IncidentType is a multivalued report parameter, you can't use @IncidentType Is NULL in your report's Dataset Query because it messes up the sql code and it become unpredictable.

    Also "A multi-value parameter cannot include null values" so it's useless to check if the parameter Is Null. You could maybe use a possible workaround like this:

     AND ('NULL_FLAG' IN (@IncidentType) OR event_definition_rv.event_definition_id IN (@IncidentType))
    

    See docs.microsoft.com where it says:

    • The query must use an IN clause to specify the parameter.

    Note:

    The report server rewrites queries for data sources that cannot process parameters as an array. Rewriting the query is necessary to produce the intended result. A query rewrite is triggered when a parameter is defined as multivalued and the query uses an IN statement to specify the parameter. If you build a query that does not include the IN statement, be aware that you are circumventing the logic the report server provides to support multivalued parameters.

    0 讨论(0)
  • 2020-12-11 12:19

    Try casting the unsplit values as uniqueidentifier:

        ;WITH Cte AS 
    ( 
        SELECT 
            1 as id, 
            CAST('<M>' + REPLACE( (select @IncidentType),  ',' , '</M><M>') + '</M>' AS XML) AS Names 
    ) 
    SELECT 
        id, 
        CAST(Split.a.value('.', 'VARCHAR(MAX)') AS UNIQUEIDENTIFIER) AS Names
    INTO #incident_types
    FROM Cte 
    CROSS APPLY Names.nodes('/M') Split(a)
    
    0 讨论(0)
提交回复
热议问题