[英]SSRS Multivalue Parameter in Dataset Query issue
我的报表中有一个嵌入式数据集,我将参数传递给该数据集。
这对于使用=符号在我的And行中进行单选工作正常,我认为,Google结果似乎在说我可以将=符号更改为“ IN”
FROM [database].[dbo].[itemTable]
right Outer Join [database].[dbo].[CategoryTable]
on [database].[dbo].[itemTable].Category= [database].[dbo].[CategoryTable].Category And ([database].[dbo].[itemTable].Region = @pRegion) And ([database].[dbo].[itemTable].CategoryLN = @pCategoryLN )
where [database].[dbo].[CategoryTable].Category != 'RETIRED'
以上工作正常,但如果我更改为
[database].[dbo].[itemTable].Region IN @pRegion'
查询窗口在“ @pRegion”附近显示语法不正确。
我们已经通过使用数据库表值函数(可能在Internet上的某个地方找到了,但我不记得在哪里)解决了这个问题
CREATE FUNCTION [database].[dbo].[ParamSplit]
(
@List nvarchar(max), -- string returned from multivalue report parameter
@SplitOn nvarchar(5) -- separator character
)
RETURNS @RtnValue table
(
Id int identity(1,1),
Value nvarchar(100)
)
AS
BEGIN
While (Charindex(@SplitOn,@List)>0)
Begin
Insert Into @RtnValue (value)
Select Value = ltrim(rtrim(Substring(@List,1,Charindex(@SplitOn,@List)-1)))
Set @List = Substring(@List,Charindex(@SplitOn,@List)+len(@SplitOn),len(@List))
End
Insert Into @RtnValue (Value)
Select Value = ltrim(rtrim(@List))
Return
END
然后,您可以在数据集查询中使用它。
where [database].[dbo].[itemTable].Region IN (Select [dbo].[ParamSplit].[Value] from [database].[dbo].[ParamSplit](@pRegion,','))
看起来您所缺少的只是参数周围的括号 。
[database].[dbo].[itemTable].Region IN (@pRegion)
还要确保您不编辑/解析参数值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.