我正在开发一个 SSRS 2008 R2 RDL 文件。现在,我正在尝试添加一个应该是多选的报告参数。以前我使用过多选参数,但它们以前一直是 CHARACTER 数据类型。所以在我的主数据集中我的代码是:
;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)
(在我的 RDL 文件中,这个 IncidentType 报告参数允许多选)
但是现在 IncidentType 是一个 UNIQUEIDENTIFIER 数据类型。我已经尝试过 SSRS JOIN 函数,但是当我运行它时,这仍然给我在 SSRS 中的相同错误:
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.
我如何通过传入多个唯一标识符来为此编码?
我尝试了您发布的以下解决方案:
CAST(Split.a.value('.', 'VARCHAR(MAX)') AS UNIQUEIDENTIFIER) AS Names
但这现在给了我这个错误:
Msg 8169, Level 16, State 2, Line 62
Conversion failed when converting from a character string to uniqueidentifier.
在我的 sproc 的顶部,我有:
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'
但导致此错误的行是:
AND (@IncidentType is NULL OR event_definition_rv.event_definition_id in (SELECT Names FROM #incident_types))
因为我可以毫无错误地运行这些行:
select * from #incident_types
select * from #facilities