博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sql server reporting service multi select parameter
阅读量:5017 次
发布时间:2019-06-12

本文共 3435 字,大约阅读时间需要 11 分钟。

解决reporting service 多选列表参数的办法有两种:

 1. 给tablix添加Filter。

 2. 使用存储过程parse多值参数。

具体操作如下。

I agree, its a little messy to use multi-parameters.  There are two primary methods I use to handle this:  Filters and SQL.  The Filter method is easier.

Filter Method:

  1. Create a multi-value parameter.  Let's call it @Animals and you select Dog, Cat, Bird (or Select All)
  2. Your main Dataset, which will return a result set to your report, does not reference @Animals in it's where clause.
  3. Instead, click on Dataset Properties and select Filters
  4. In the Filter setup dialog, click on the column in your result set that corresponds to the Animal value.
  5. For the operator, select the "In" operator
  6. For the value, type in [@Animals]
  7. Done!

This will "post-filter" your SQL query and only return the values that have been filtered by your multi-value parameter.  Only Dog, Cat, Bird records will return to your report.  The downside to this approach is that the processing occurs at the Report Server level and not by your Database server, because you are not using SQL to do the work.  In many cases (most cases!) I find this the easiest and quickest way to do what you want.

SQL Method:

  1. Create a multi-value parameter.  Let's call it @Animals and you select Dog, Cat, Bird (or Select All).  Same as the Filter Method!
  2. You will need a stored procedure for your main report Result Dataset.  Let's call it sp_get_animals.
  3. sp_get_animals will take one argument, @Animals, so the calling mechanism looks like this:  exec sp_get_animals @Animals
  4. When you are configuring your parameters in the Query dialog, use the following expression to define the value of your parameter:  =join(Parameters!Animals.Value,",")
  5. This will create a string that looks like this:  "Bird,Dog,Cat"
  6. In the body of your stored procedure, you will have to parse @Animals to pick off Bird, Dog, Cat.
  7. Once you have parsed @Animals, you can use the SQL IN clause to actually process it.

This method is definitely more complicated, but it has the advantage of passing the parameters directly to SQL and allows you to take advantage of your Database Server.

When in doubt, use the Filter method if you can get away with it.  It has the advantage of simpler SQL, and more intuitive to other members of your team.

There are many examples of the SQL method on this website, and a quick Google search will also reveal examples of using SQL to do this.  But like I said, it can be messy.

 

附上Parse多值参数的function

CREATE function [dbo].[SplitString] ( @Input nvarchar(max), --input string to be separated     @Separator nvarchar(max)=',', --a string that delimit the substrings in the input string     @RemoveEmptyEntries bit=1 --the return value does not include array elements that contain an empty string ) returns @TABLE table ( [Id] int identity(1,1), [Value] nvarchar(max) ) as begin declare @Index int, @Entry nvarchar(max) set @Index = charindex(@Separator,@Input) while (@Index>0) begin set @Entry=ltrim(rtrim(substring(@Input, 1, @Index-1))) if (@RemoveEmptyEntries=0) or (@RemoveEmptyEntries=1 and @Entry<>'') begin insert into @TABLE([Value]) Values(@Entry) end set @Input = substring(@Input, @Index+datalength(@Separator)/2, len(@Input)) set @Index = charindex(@Separator, @Input) end set @Entry=ltrim(rtrim(@Input)) if (@RemoveEmptyEntries=0) or (@RemoveEmptyEntries=1 and @Entry<>'') begin insert into @TABLE([Value]) Values(@Entry) end return end

转载于:https://www.cnblogs.com/philzhou/articles/2257543.html

你可能感兴趣的文章
JDK和Tomcat部署时,版本不同的问题解决
查看>>
Imageloader、Glide、Fresco的性能及加载速度比较
查看>>
在Linux下编写php扩展
查看>>
唯一域 表示添加域时候必填
查看>>
JDK8日期时间库 例子
查看>>
懒人必备的移动端定宽网页适配方案
查看>>
(转)Android 、BlackBerry 文本对齐方式对比
查看>>
windows 上启动appium
查看>>
自己动手设计并实现一个linux嵌入式UI框架
查看>>
Codeforces Round #447
查看>>
小米笔记本安装Ubuntu后,无法扫描到wifi解决办法
查看>>
PHP学习之没有权限修改hosts文件
查看>>
mybatis~2
查看>>
JS实现多物体动画
查看>>
react单页面应用的Nginx配置问题
查看>>
女人的出路在何方?
查看>>
如何在Pycharm设置ES6语法环境
查看>>
python函数回顾:dir()
查看>>
Hadoop基准测试
查看>>
Flask_admin 笔记一 (快速启用)
查看>>