Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

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

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 but they have always been CHARACTER data types before. So in my main dataset my code was:

;WITH Cte AS 
( 
    SELECT 
        1 as id, 
        CAST('<M>' + REPLACE( (select @IncidentType),  ',' , '</M><M>') + '</M>' AS XML) AS Names 
) 
SELECT 
    id, 
    Split.a.value('.', 'VARCHAR(MAX)') AS Names
INTO #incident_types     
FROM Cte 
CROSS APPLY Names.nodes('/M') Split(a)

(And in my RDL file this IncidentType report parameter allows multiselect)

But now IncidentType is a UNIQUEIDENTIFIER datatype. I have tried the SSRS JOIN function but this is still giving me same error in SSRS when I run this:

An error has occurred during report processing. (rsProcessingAborted)
Query execution failed for dataset 'Incidents'. (rsErrorExecutingCommand)
Conversion failed when converting from a character string to uniqueidentifier. 

How do I code for this by passing in multiple uniqueidentifiers?

I tried the solution below that you posted:

CAST(Split.a.value('.', 'VARCHAR(MAX)') AS UNIQUEIDENTIFIER) AS Names

But this gave me this error now:

Msg 8169, Level 16, State 2, Line 62
Conversion failed when converting from a character string to uniqueidentifier.

At the top of my sproc I have:

declare
    @FacilityID varchar(MAX) = null,
    @ProgramID uniqueidentifier = null,
    @ServiceDateStart smalldatetime = null,
    @ServiceDateEnd smalldatetime = null,
    @IncidentType varchar(MAX) = null

SET @IncidentType = '864EA130-F36B-4958-B51F-EE9DBD35D804,671A8EB3-8298-40DB-BD66-93309904E463,ACA1EB55-3D66-467B-8388-CC42FCFB00F3
SET @FacilityID = '83B465B8-28DD-4F37-9F2D-A4D5E38EE7FB,3EC657F7-655F-43FB-8424-2A8914E7C725,B2064474-5C9B-4884-B1D7-4FCE1C804DF7'

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))

cause I can run these lines without errors:

select * from #incident_types
select * from #facilities
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...