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

佐手、 提交于 2019-11-28 12:53:36

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)

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!