简体   繁体   English

即使数据库中没有关联的记录,也会在ssrs报表中显示传递的参数

[英]display passed parameter in an ssrs report even if there are no associated records in the database

I need to create an SSRS report that is passed a list of parameters and return all the parameters, even if there are no records associated with the parameter. 我需要创建一个传递参数列表并返回所有参数的SSRS报告,即使没有与该参数关联的记录也是如此。 I have posted below of what I am trying to accomplish. 我在下面发布了我要完成的工作。

Passed parameters: 12388501, 1238853, 1238858, 123885900, 12388573 通过的参数:12388501、1238853、1238858、123885900、12388573

And would like the final report to look like the example below: 并希望最终报告看起来像下面的示例: 在此处输入图片说明

The parameters passed in this example are Account Numbers. 在此示例中传递的参数是帐号。 How can I get the Account Number to display as a record even though it is not contained in the database? 即使数据库中未包含该帐号,如何获取显示为记录的帐号?

I am using SQL Server 2012 database, SSMS for development of the query and will ultimately create the report in SSRS. 我正在使用SQL Server 2012数据库,SSMS进行查询开发,并将最终在SSRS中创建报告。 I hope my wording of this question makes sense. 我希望我对这个问题的措辞有意义。 If there is anything missing in my query please let me know and I will provide it. 如果我的查询中缺少任何内容,请告诉我,我会提供。 Thanks in advance! 提前致谢!

Step 1: Split your string into rows of a table. 第1步:将字符串拆分为表格的各行。 My understanding is that Erland Sommarskog is regarded as an authority on handling lists in SQL Server: Arrays and Lists in SQL Server 2008 Using Table-Valued Parameters (revised in 2012. He has a page devoted to the broader topic/earlier SQL Server versions at Arrays and Lists in SQL Server .) There are other methods for splitting strings into table-valued parameters via user-defined functions, etc. that may perform reasonably well for small lists similar to what you have here. 我的理解是,Erland Sommarskog被视为处理SQL Server中的列表的权威: 使用表值参数的SQL Server 2008中的数组和列表 (于2012年修订。他在以下页面上专门讨论了更广泛的主题/早期的SQL Server版本: SQL Server中的数组和列表 。)还有其他方法,可以通过用户定义的函数等将字符串拆分为表值参数,对于与您在此处的小列表类似的方法,可能会表现良好。

Step 2: using that table-valued parameter that you've populated from the splitting of the string parameter, form your query like the one below. 第2步:使用您从字符串参数拆分中填充的表值参数,形成与下面的查询类似的查询。 The INNER JOIN in the first SELECT will give you only those records that match an AccountNumber in your inline table and the LEFT OUTER JOIN with the WHERE clause in the second SELECT will give you only AccountNumber values that don't exist in myTable. 第一个SELECT中的INNER JOIN将只为您提供与内联表中的AccountNumber匹配的那些记录,而第二个SELECT中的LEFT OUTER JOIN与WHERE子句将为您提供myTable中不存在的AccountNumber值。 You can substitute other values for the NULL values I've stubbed in as long as they match the data types of the corresponding fields in myTable. 您可以将其他值替换为我存根的NULL值,只要它们与myTable中相应字段的数据类型匹配即可。

SELECT mt.AccountNumber,mt.LastName,mt.FirstName,mt.ContactNumber,mt.Address,mt.City,mt.State,mt.Zip 
FROM myTable mt JOIN @t t ON mt.AccountNumber = t.AccountNumber
UNION
SELECT t.AccountNumber,NULL LastName,NULL FirstName,NULL ContactNumber,NULL Address,NULL City,NULL State, NULL Zip 
FROM @t t
LEFT OUTER JOIN myTable mt ON t.AccountNumber = mt.AccountNumber 
WHERE mt.AccountNumber IS NULL

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

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