简体   繁体   English

SSRS多选参数错误

[英]SSRS Multiselect parameter error

I have a project that I need to add a param to that accepts multiple values. 我有一个项目,需要在其中添加一个接受多个值的参数。 While this should sound pretty easy it is not working. 虽然这听起来很容易,但无法正常工作。

Here is the param: @queue_group varchar(100) 这是参数: @queue_group varchar(100)

And here is how it is used: and g.extension in (@queue_group) 这是它的用法: and g.extension in (@queue_group)

Now when I manually do it like so: and g.extension in ('700', '702') it works just fine. 现在,当我这样手动操作时:和g.extension in ('700', '702')就可以正常工作。 I have to make the numbers a string because of how the column was setup it has some string values in it such as *86 that breaks when I just do 700, 702 . 我不得不做出的数字,因为该列是如何设置它在它如* 86的一些字符串值,打破时,我只是做一个字符串700, 702

Now I set up the param in SSRS giving it available values and allowing multiple select but every time it doesn't work because it can't find any results. 现在,我在SSRS中设置了参数,为其提供了可用的值并允许进行多次选择,但是每次都无法使用时,因为它找不到任何结果。 The ultimate error is a divide by zero which is because it isn't finding any records. 最终错误是除以零,这是因为它没有找到任何记录。

How can I make SSRS mimic my manual behavior of '700', '702' which when I remove the param and enter that manually it runs just fine. 如何使SSRS模仿我的手动行为'700', '702' ,当我删除参数并手动输入参数时,它运行良好。

In SSRS I've tried Available Values CS = 700, CS = '700', CS = =Cstr(700) and CP = 702, CP = '702', CP = =CStr(702) . 在SSRS中,我尝试了Available Values CS = 700, CS = '700', CS = =Cstr(700) and CP = 702, CP = '702', CP = =CStr(702)

I've now tried setting up a table and using that as the defined values for the parameter. 我现在尝试建立一个表并将其用作参数的定义值。 It now works when I select a single option and returns results. 现在,当我选择一个选项并返回结果时,它可以工作。 whenever I select 2 it returns me 0 results. 每当我选择2时,都会返回0个结果。

I'm at a loss. 我很茫然。

SSRS can support multi-value parameters without much extra work so long as the dataset is in ssrs. 只要数据集在ssrs中,SSRS即可支持多值参数而无需进行过多工作。

Here is a link to the tech net on it: https://technet.microsoft.com/en-us/library/aa337396(v=sql.105).aspx 这是其上的技术网的链接: https : //technet.microsoft.com/zh-cn/library/aa337396(v=sql.105).aspx

What happens is that SSRS passes the whole query to the sql compiler, this means that the replacement of the parameter with the multi-value string happens before compile. 发生的事情是SSRS将整个查询传递给sql编译器,这意味着在编译之前就发生了用多值字符串替换参数的情况。 So I don't think that's the problem, because If it were an error in the way the multi-value param was presenting the data to the compiler it would not be a divide by zero. 因此,我认为这不是问题所在,因为如果多值参数将数据提供给编译器的方式出错,那么它将不会被零除。

Instead I'm thinking this has to do with how the parameter is populated. 相反,我认为这与参数的填充方式有关。 You have the param set to a text field, so people are expected to enter their own values. 您已将参数设置为文本字段,因此人们应该输入自己的值。 However SSRS handles the formating for a text field before it's sent to compile, and I'm guessing that's what tripping you up. 但是,SSRS在发送文本字段进行编译之前会处理该字段的格式,我想这就是您的绊脚石。

If you enter "402,407" without the quotes into the param at compile time it will be transformed into: 如果在编译时在参数中输入“ 402,407”而不加引号,它将被转换为:

and g.extension in ('402,407')

That would not return any results. 那不会返回任何结果。 If this is just a report you use, you could enter: "402','407" without the double quotes and at compile time it would transform it too: 如果这只是您使用的报告,则可以输入:“ 402','407”,不带双引号,并且在编译时也会对其进行转换:

 and g.extension in ('402','407')

The better solution would be to create a data set for the param, set the parameter to use that data set as it's list of available values, and check the multi-value property for the param. 更好的解决方案是为参数创建数据集,设置参数以使用该数据集作为可用值列表,并检查参数的多值属性。 That way you would select multiple values from a drop down, and the user wouldn't have to mess with the string formatting. 这样,您可以从下拉列表中选择多个值,并且用户不必弄乱字符串格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM