简体   繁体   English

多值参数截断

[英]Multi-value parameter truncation

On my SSRS report I have a multi-value parameter which contains 250+ uniqueidentifier data type values. 在我的SSRS报告中,我有一个多值参数,其中包含250多个uniqueidentifier数据类型值。 This works fine with a small selection of values in the parameter dropdown, but when user chooses (select all), they get this error: 这在参数下拉列表中的一小部分值中可以正常工作,但是当用户选择(全选)时,它们会收到以下错误:

An error occurred during local report processing.
String or binary data would be truncated. 

Each uniqueidentifier field is 36 characters long, which means 250 of them added together result in a 9000 character string. 每个uniqueidentifier字段长度为36个字符,这意味着其中250个加在一起会产生9000个字符的字符串。 This is what causes the truncation to occur. 这是导致截断发生的原因。

What approach should I take to handle this situation? 我应该采取什么方法来处理这种情况?

Edit: 编辑:

Couple snapshots of the stored procedure: 存储过程的几个快照:

ALTER PROCEDURE [dbo].[spReport]
     @StartDate as datetime
    ,@EndDate as datetime
    ,@LocationId uniqueidentifier
    ,@UserIds uniqueidentifier

@UserIds is the multi-value parameter. @UserIds是多值参数。 It is used in the where clause of the query: 它用在查询的where子句中:

WHERE (U.UserId IN (@UserIds) OR @UserIds IS NULL)

SSRS does have a limit on the size of multi-value parameters. SSRS确实限制了多值参数的大小。 I can't remember what it is off the top of my head, but I think you are well beyond it. 我不记得它是什么,但我觉得你已经超越了它。 (SSRS converts the multi-value parameter to a comma separated string and replaces the occurances of the variable name in the query with the string.) (SSRS将多值参数转换为逗号分隔的字符串,并使用字符串替换查询中变量名称的出现。)

So as mentioned in the comments, you've got two problems: 正如评论中提到的,你有两个问题:

  1. SP's can't take multi-value parameters directly from SSRS. SP不能直接从SSRS获取多值参数。 You'll need to do some manipulation. 你需要做一些操纵。
  2. Your overall parameter length. 您的整体参数长度。 This may require a little bit of creativity to solve. 这可能需要一点点创造力才能解决。 Some options: 一些选择:

    • Can you supply either a separate parameter or a special value in your existing parameter for <All Users> and then check for this in the SP, returning all values in that case. 您可以在<All Users>现有参数中提供单独的参数或特殊值,然后在SP中检查这一点,在这种情况下返回所有值。 If the query is directly in SSRS (instead of a SP) something like this would work: 如果查询直接在SSRS(而不是SP)中,这样的事情会起作用:

       ...WHERE ( U.UserId in ( @UserIds) OR '<All Users>' in ( @UserIds ) ) ... 
    • Can you filter the number of items in your parameter, based on earlier parameters? 您可以根据之前的参数过滤参数中的项目数吗? Such as have the user select a date range and/or department, and only return UIDs that match that range? 比如让用户选择日期范围和/或部门,只返回与该范围匹配的UID?

You can't use an SSRS multi-value parameter with a stored procedure like that. 您不能将SSRS多值参数与此类存储过程一起使用。 You'll need to join the values in the report, pass them as a varchar(max), and then split them in the stored procedure: 您需要加入报表中的值,将它们作为varchar(max)传递,然后在存储过程中将它们拆分:
https://stackoverflow.com/a/9862901/124386 https://stackoverflow.com/a/9862901/124386
http://www.codeulike.com/2012/03/ssrs-multi-value-parameters-with-less.html http://www.codeulike.com/2012/03/ssrs-multi-value-parameters-with-less.html

另一种方法是创建用户定义的表类型,并使用它而不是varchar来传递选定的值。

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

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