加入SSRS中的数据集

时间:2016-10-14 20:59:31

标签: reporting-services ssrs-2012

我在SSRS中有两个数据集。我想在一份报告中加入他们。

第一个是产品列表,其中productnumber为密钥和builddate。

productnumber builddate
123           6/1/2005 
123           6/1/2015 

第二个是具有有效日期的辅助标识符。

表格如下:

productnumber secondarynumber effectivedate obsoletedate
123           999             1/1/2000      12/31/2009
123           999A            1/1/2010      1/1/2030

我希望报告看起来像这样:

productnumber builddate secondarynumber
123           6/1/2005  999
123           6/1/2015  999A

这可能吗?我尝试使用查找和LookupSet返回secondarynumber但我' m,在关于如何通过过滤器PARAMS中或如何使用一个记录集输出的损失。我觉得我错过了什么。

1 个答案:

答案 0 :(得分:2)

T-SQL Solution (Easiest if your datasource is a database and you are not restricted to use unmodifiable stored procedures)

If your datasource is a database you can handle it easily from a T-SQL query, by performing a JOIN between both tables and specify a WHERE clause to select only the rows matching the condition: effectivedate <= buildDate =< obsoletedate.

SELECT a.Productnumber, 
       a.Builddate, 
       b.Secondarynumber 
FROM   Dataset1table a 
       INNER JOIN Dataset2table b 
               ON a.Productnumber = b.Productnumber 
WHERE  a.Builddate BETWEEN b.Effectivedate AND b.Obsoletedate  

SSRS Solution:

Go to Report menu / Report properties... under the Code tab add the following VB function.

Public Function GetSecondaryNumber(buildDate As Date ,
effectiveDate As Object, obsoleteDate As Object, secondaryNumber As Object) As String

Dim i As Integer    

For i = 0  To effectiveDate.Length -1 
  if buildDate >= effectiveDate(i) and buildDate <= obsoleteDate(i) then
     Return secondaryNumber(i)
   End If
Next 

Return ""

End Function

Then in the secondarynumber column in your tablix use:

=Code.GetSecondaryNumber(
Fields!builddate.Value,
LookupSet(Fields!productnumber.Value,Fields!productnumber.Value,Fields!effectivedate.Value,"DataSet2"),
LookupSet(Fields!productnumber.Value,Fields!productnumber.Value,Fields!obsoletedate.Value,"DataSet2"),
LookupSet(Fields!productnumber.Value,Fields!productnumber.Value,Fields!secondarynumber.Value,"DataSet2")
)

It will work if you don't have Nulls in effectiveDate and obsoleteDate columns. Otherwise you will have to handle null validation in the VB function or SSRS.

Let me know if this helps.

相关问题