SQL for DB2中的多参数,使用SSRS

时间:2013-03-26 13:41:23

标签: sql db2 ssrs-2008 peoplesoft

我对SSRS for Sql Server非常新。使用2008.我的工作要求我使用这个工具重现一些遗留报告 - 我创建了参数的下拉列表,并遇到了DB2不支持多参数的错误。我们使用PeopleSoft表。我的工作现在说,找到一个解决方法。我一直在阅读很多论坛,但我无法获得任何实际情况。任何人都可以提供资源或指导我完成我需要做的事情来强制此报告以允许我的用户选择多个参数吗?

SELECT AL1.EMPLID, AL1.NAME,
       AL4.COVERAGE_ELECT, AL4.FLAT_AMOUNT,
       AL1.JOBTITLE, AL1.JOB_FAMILY,
       AL3.ANNUAL_RT, AL3.ANNL_BENEF_BASE_RT,
       AL4.BENEFIT_PLAN
FROM TABLEONE AL1,
     TABLETWO AL2,
     TABLETHREE AL3,
     TABLEFOUR AL4
WHERE (AL1.EMPLID = AL3.EMPLID
       AND AL1.EMPL_RCD = AL3.EMPL_RCD
       AND AL1.EMPLID = AL2.EMPLID
       AND AL1.EMPL_RCD = AL2.EMPL_RCD
       AND AL1.EMPLID = AL4.EMPLID
       AND AL1.EMPL_RCD = AL4.EMPL_RCD)
       AND (AL2.EFFDT = (SELECT MAX(LF.effdt)
                         FROM TABLETWO LF
                         WHERE LF.emplid = al2.emplid
                               AND LF.empl_rcd = al2.empl_rcd
                               AND LF.plan_type = al2.plan_type
                               AND LF.benefit_nbr = al2.benefit_nbr
                               AND LF.effdt <= CURRENT Date)
            AND AL2.PLAN_TYPE = '20'
            AND AL2.COVERAGE_ELECT = 'E'
            AND AL3.EFFDT = (SELECT MAX(J.EFFDT)
                             FROM TABLETHREE J
                             WHERE J.EMPLID = AL3.EMPLID
                                   AND J.EMPL_RCD = AL3.EMPL_RCD
                                   AND J.EFFDT <= CURRENT Date)
            AND AL3.EFFSEQ = (SELECT MAX(ES.EFFSEQ)
                              FROM TABLETHREE ES
                              WHERE ES.EMPLID = AL3.EMPLID
                                    AND ES.EMPL_RCD = AL3.EMPL_RCD
                                    AND ES.EFFDT = AL3.EFFDT)
            AND AL4.EFFDT = (SELECT MAX(L.EFFDT)
                             FROM TABLETWO L
                             WHERE L.EMPLID = AL4.EMPLID
                                   AND L.EMPL_RCD = AL4.EMPL_RCD
                                   AND L.PLAN_TYPE = AL4.PLAN_TYPE
                                   AND L.BENEFIT_NBR = AL4.BENEFIT_NBR
                                   AND L.EFFDT <= CURRENT Date)
            AND AL4.PLAN_TYPE IN (?)
            AND AL4.COVERAGE_ELECT= ?)

3 个答案:

答案 0 :(得分:1)

以下是如何使用多个参数获取变通方法的链接,如果不能帮助您更多地发布您所做的事情,我们会找到答案,几个星期前我处理过类似的问题。这是链接:http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/A_8737-SSRS-can-be-also-used-for-user-inputs.html

基本上我做了什么:1。我连接到dataSource。然后我设置了我的DataSet。在数据集中,您可以输入您提供的select语句,或者如果您使用的是存储过程,也可以选择该选项。 在VS中有一个名为Parameters的文件夹。您可以在那里添加两个参数。将其设置为可见。我允许空值和空值,以防用户选择任何内容。我为下拉列表指定了值。这一切都在创作方面。 现在您可以返回到您的数据集并添加一行:

WHERE column = + @DropdownParameter +
AND column2 = +@Dropdown2Parameter +

我只是编写您感兴趣的代码部分。我没有对它进行测试,但这与我在项目中的方式类似,并且有效。

FROM TABLETWO
        WHERE PLAN_TYPE = +@DropdownParameter+
              AND EFFDT <= CURRENT_DATE
        GROUP BY EMPLID, EMPL_RCD, BENEFIT_NBR, PLAN_TYPE) INC
    ON T4.EMPLID = INC.EMPLID
       AND T4.EMPL_RCD = INC.EMPLRCD
       AND T4.BENEFIT_NBR = INC.BENEFIT_NBR
       AND T4.PLAN_TYPE = INC.PLAN_TYPE
       AND T4.EFFDT = INC.EFFDT
  WHERE T4.COVERAGE_ELECT = +@DropdownParameter2+) AL4
ON AL4.EMPLID = AL1.EMPLID
 AND AL4.EMPL_RCD = AL1.EMPL_RCD

答案 1 :(得分:1)

......哇,这是一些疑问。这与您的问题无关,但应自行清理查询。除其他外,请始终明确指定您的联接,不要使用逗号分隔的FROM子句。

这个可能稍微好一些:

SELECT AL1.EMPLID, AL1.NAME,
       AL4.COVERAGE_ELECT, AL4.FLAT_AMOUNT,
       AL1.JOBTITLE, AL1.JOB_FAMILY,
       AL3.ANNUAL_RT, AL3.ANNL_BENEF_BASE_RT,
       AL4.BENEFIT_PLAN
FROM TABLEONE AL1,
JOIN (SELECT DISTINCT EMPLID, EMPL_RCD
      FROM TABLETWO 
      WHERE PLAN_TYPE = '20'
            AND COVERAGE_ELECT = 'E'
            AND EFFDT <= CURRENT_DATE) AL2
  ON AL2.EMPLID = AL1.EMPLID
     AND AL2.EMPL_RCD = AL1.EMPL_RCD
JOIN (SELECT T3.EMPLID, T3.EMPL_RCD, T3.ANNUAL_RT, T3.ANNL_BENEF_BASE_RT
      FROM TABLETHREE T3
      JOIN (SELECT a.EMPLID, a.EMPL_RCD, a.EFFDT, MAX(EFFSEQ) EFFSEQ
            FROM (SELECT EMPLID, EMPL_RCD, MAX(EFFDT) EFFDT
                  FROM TABLETHREE 
                  GROUP BY EMPLID, EMPL_RCD) a
            JOIN TABLETHREE z
              ON z.EMPLID = a.EMPID
                 AND z.EMPL_RCD = a.EMPL_RCD
                 AND z.EFFDT = a.EFFDT
            GROUP BY a.EMPLID, a.EMPL_RCD, a.EFFDT) INC
        ON INC.EMPLID = T3.EMPLID
           AND INC.EMPL_RCD = T3.EMPL_RCD
           AND INC.EFFDT = T3.EFFDT
           AND INC.EFFSEQ = T3.EFFSEQ) AL3
  ON AL3.EMPLID = AL.EMPLID
     AND AL3.EMPL_RCD = AL1.EMPL_RCD
JOIN (SELECT T4.EMPLID, T4.EMPL_RCD, 
             T4.COVERAGE_ELECT, T4.FLAT_AMOUNT, T4.BENEFIT_PLAN
      FROM TABLEFOUR T4
      JOIN (SELECT EMPLID, EMPL_RCD, BENEFIT_NBR, PLAN_TYPE, MAX(EFFDT) EFFDT
            FROM TABLETWO
            WHERE PLAN_TYPE IN (?)
                  AND EFFDT <= CURRENT_DATE
            GROUP BY EMPLID, EMPL_RCD, BENEFIT_NBR, PLAN_TYPE) INC
        ON T4.EMPLID = INC.EMPLID
           AND T4.EMPL_RCD = INC.EMPLRCD
           AND T4.BENEFIT_NBR = INC.BENEFIT_NBR
           AND T4.PLAN_TYPE = INC.PLAN_TYPE
           AND T4.EFFDT = INC.EFFDT
      WHERE T4.COVERAGE_ELECT = ?) AL4
  ON AL4.EMPLID = AL1.EMPLID
     AND AL4.EMPL_RCD = AL1.EMPL_RCD

(未经测试 - 在不知道您的数据布局的情况下有点困难。如果有更多可用信息,可能会更进一步简化事情;特别是如果TABLETHREE.EFFSEQ总是增加,或者至少每{{1} },该部分可以折叠为一个参考)

答案 2 :(得分:1)

为所有参数使用多个问号。确保将每个问号与参数匹配,并按正确的顺序匹配它们。与其他一些遗留数据库(例如Ingres DB)一样,IBM DB2在查询中不支持命名参数,因此,对所有参数使用[?]。其余步骤与您的其他报告设计相同。

我认为这还取决于您使用哪种驱动程序进行报告。这是我用于DB2报告的驱动程序。它来自Quest公司的TOAD Analyze。

IBM DB2 ODBC DRIVER - TACOM27

这是您的查询:

从tableA

中选择*

where field1 =?

和field2 =?

这些是您的参数:

? = [@ para1]

? = [@ para2]