我的SSRS文本框表达式有什么问题?

时间:2019-04-10 15:17:57

标签: c# reporting-services expression

我正在为捐赠创建RDLC报告。我有dataset1,其中包括一个SVC表和一个DOR表。在我的表达式中,我能够在SVC表中获取美元金额,但是,我无法从DOR表中获取组织名称。我正在尝试做的事情:

  1. 查看每个由SVC_IDNUM标识的记录
  2. 从捐赠字段中获取值(例如SVC_DN01PY, SVC_DN02PY, SVC_DN03PY
  3. SVC_DONCOD(捐赠代码)获取价值,并与DOR_ORGNUM代码匹配,并获取相应的DOR_ORGNAM(组织名称)。

捐赠金额有效,但组织名称无效。我对SSRS不熟悉,一直在寻找解决方案。我想念什么或做错什么了?

我一直在尝试使用JoinLookupSet来实现这一目标。

="Donations: " & Join(LookupSet(Fields!SVC_IDNUM.Value,Fields!SVC_IDNUM.Value,
 IIF(Fields!SVC_DONCOD.Value = Fields!DOR_ORGNUM.Value, Fields!DOR_ORGNAM.Value &" ", " ") & IIF(Fields!SVC_DN01PY.Value > 0, Fields!SVC_DN01PY.Value &" ", " ") &
 IIF(Fields!SVC_DONCOD.Value = Fields!DOR_ORGNUM.Value, Fields!DOR_ORGNAM.Value &" ", " ") & IIF(Fields!SVC_DN02PY.Value > 0, Fields!SVC_DN02PY.Value &" ", " ") &
 IIF(Fields!SVC_DONCOD.Value = Fields!DOR_ORGNUM.Value, Fields!DOR_ORGNAM.Value &" ", " ") & IIF(Fields!SVC_DN03PY.Value > 0, Fields!SVC_DN03PY.Value &" ", " "),"DataSet1"))

我还包括了DataSet1的SQL查询。这是一个冗长的查询,因为该报告需要很多信息。

string query1 = "SELECT FJSSVBAT.SVB_BATNBR, FORMAT(FJSSVBAT.SVB_CHKDAT,'MM/dd/yyyy'),
FJSWHEEL.WHL_IDNUM, FJSWHEEL.WHL_FSTNAM, FJSWHEEL.WHL_MIDNAM, FJSWHEEL.WHL_LSTNAM, 
FJSWHEEL.WHL_SUFFIX, FJSWHEEL.WHL_ADDR1, FJSWHEEL.WHL_ADDR2, FJSWHEEL.WHL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JOIN FJSSVDTL ON FJSWHEEL.WHL_IDNUM = FJSSVDTL.SVD_IDNUM AND
FJSSVDTL.SVD_BATNBR = @BatchNumber FULL OUTER JOIN DONORG CROSS JOIN FJSDSCTL WHERE
(FJSSVBAT.SVB_BATNBR = @BatchNumber) AND () ORDER BY FJSSVCTL.SVC_CHKNBR";

SVC_DONCOD.Value为1,DOR_ORGNUM.Value为1,DOR_ORNAM.Value将是United Way,而SVC_DN01PY.Value为$ 7.16 文本框中的结果应为United Way $ 7.16。这是报告一部分的屏幕截图,这是报告中许多记录的一个记录。红线表示我的雇主需要的单个文本框,其中必须包含组织名称和捐赠金额。 enter image description here

1 个答案:

答案 0 :(得分:0)

您的Lookupset()表达式错误。根据您之间的关系,您可以使用Lookup()(对于1:1关系)和LookupSet()(对于1:n关系)显示数据。我认为通过此示例,您应该能够使您的报告生效。我不确定您的桌子如何,但我假设是这样的:

1:1关系

'Dataset1

 SVC_DONCOD1   Amount
     1          20€
     2          30€

'Dataset2

SVC_DONCOD2   CompanyName
    1          Test1
    2          Test2

如果将Dataset2放在Tablix中,则可以显示SVC_DONCOD2CompanyName。要同时显示Amount,请在详细信息文本框中添加以下表达式:

=Lookup(Fields!SVC_DONCOD2.Value, Fields!SVC_DONCOD1.Value, Fields!Amount.Value, "Dataset1")

结果:

 SVC_DONCOD2   Amount   CompanyName
     1          20€        Test1
     2          30€        Test2

1:n关系

 SVC_DONCOD1   Amount
     1          20€
     2          30€
     1          10€
     1          10€

'Dataset2

SVC_DONCOD2   CompanyName
    1          Test1
    2          Test2

再次将Dataset2放在Tablix中,这次添加以下表达式:

=LookupSet(Fields!SVC_DONCOD2.Value, Fields!SVC_DONCOD1.Value, Fields!Amount.Value, "Dataset1")

结果:

 SVC_DONCODE2   CompanyName  Amount
     1            Test1       20€
                              10€
                              10€
     2            Test2

注意:

如果您的密钥包含两个字段,则按如下所示进行合并:

=Lookup(Fields!Dataset1Key1.Value & Fields!Dataset1Key2.Value, Fields!Dataset2Key1.Value & Fields!Dataset2Key2.Value, Fields!Disaplay.Value, "Dataset2")