我希望我没有误解您的意图,但如果您只想让 SSRS 显示一个简单的表格,您可以让它生成一个表格对象 - 无需生成 XML .RDL 文件。但是,托管和执行的报告中有一个Export to XML 选项。
如果您只想允许用户动态添加记录,那么我现在正在做类似的事情,这就是我的解决方案。很抱歉,它相当糟糕且令人费解,但当我无法抽出时间进行更优雅的演示时,它对我来说非常有用。
首先:
UDF 为您想要的发票编号获取分隔字符串并转换为可搜索的文本数组
CREATE FUNCTION [dbo].[fnDelimitedListToVarcharTableVariable]
(
@DelimitedList nvarchar(max),
@Delimiter varchar(1)
)
RETURNS @tbl table(SplitValues nvarchar(max))
AS
BEGIN
DECLARE @DelimiterPos int
-- Find the first comma
SET @DelimiterPos = PATINDEX( '%,%', @DelimitedList)
-- If a delimiter was found, @DelimiterPos will be > 0.
WHILE @DelimiterPos > 0
BEGIN
-- Insert the value between the start of the string and the first delimiter, into the table variable.
INSERT INTO @tbl(SplitValues) SELECT CAST(LTRIM(RTRIM((SUBSTRING(@DelimitedList, 1, @DelimiterPos -1)))) AS nvarchar(max))
-- Trim the string of the first value and delimiter.
SET @DelimitedList = SUBSTRING(@DelimitedList, @DelimiterPos +1, LEN(@DelimitedList) - @DelimiterPos)
-- Look for the next delimiter in the string.
SET @DelimiterPos = PATINDEX( '%,%', @DelimitedList)
END
-- Ensure the last / only value in the @DelimitedList string gets inserted into the table variable.
INSERT INTO @Tbl(SplitValues) SELECT CAST(LTRIM(RTRIM((@DelimitedList))) AS nvarchar(max))
RETURN
END;
第二:
在您的 SSRS 报告中创建一个名为 param_DelimitedList 的参数。它应该是文本数据类型,默认值为空白字符串。
第三:
创建数据集
Create proc spGetInvoices
@param_DelimitedList varchar( max )
as
begin
Select
tbl.InvoiceNumber
,tbl.*
from MyTable tbl
where cast( tbl.InvoiceNumber as varchar(max) ) in ( select SplitValues from dbo.fnDelimitedListToVarcharTableVariable( @param_DelimitedList, ',' ) );
end;
第四:
在您的 SSRS 报告中创建一个 Tablix 表对象,其中包含来自数据集spGetInvoices的所需字段@
用户应该能够在参数框中输入发票编号列表,并将相应的数据返回到 Tablix 表对象。
代码在SQL Server 2008-R2 和Report Builder 3.0 中运行良好。希望对你有帮助。