SSRS multivalue parameter to multi-row table

痞子三分冷 提交于 2021-02-10 07:25:54

问题


I want to generate a multi-row table with a multi-value parameter.

The only thing i can do now is passing the specified parameter into every row like below:

=Parameters!P.Value(0)  
=Parameters!P.Value(1)  
...  
=Parameters!P.Value(n)

Is there a way to do it dynamically?


回答1:


Interesting question, the only I can think of is converting the parameter array into xml in a dataset, and then converting it into a table via xml nodes.

The data set parameter (lets call it @par) then should be set in a expression as:

= "<n>" + join(Parameters!P.Value,"</n><n>") + "</n>"

Then the query for the dataset will be this:

declare @parxml xml = @par
Select p.query('./text()')
from @parxml.nodes('/n') as T(p)

this will provide a table with one row per each selected parameter value.




回答2:


Finally i've found a good solution.
(remember P is a multi-value-parameter .. es. P=a;b;c;d;e)

First add a dataset that points to a table(database) made of a numeric progressive field (id) like this: (remember to load the table with a number of rows >= to the possibile number of values in your multi-value-parameter ... or simply load like 10000 rows and i think you'll be ok)

then in the report add a table with: the field id (from Dataset1) and the following expression (representing your parameter P) :

=Parameters!P.Value(Fields!id.Value)

now if you run the report you'll get something like this:

To remove the #Error rows simply filter the entire table like below, and you are done!



来源:https://stackoverflow.com/questions/41953592/ssrs-multivalue-parameter-to-multi-row-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!