将过滤器参数添加到ssrs报告中

时间:2013-07-30 14:17:57

标签: sql oracle

我有一个需要更新的查询,以允许用户过滤掉待处理的应用程序。我已经创建了参数并试图实现使用案例,但它无法正常工作或提供有关如何纠正它的任何错误消息。代码是:

select distinct pers.person_fname,
                pers.person_mname,
                pers.person_lname,
                le.nationalprovidernumber NPN,
                lic.licensenumber         LICENSE_NUMBER,
                adr.address_line1         ADDRESS1,
                adr.address_line2         ADDRESS2,
                adr.address_line3         ADDRESS3,
                adr.city                  CITY,
                sp.state_province_name    STATE,
                adr.postal_code           ZIP_CODE,
                eml.email,
                rtp.residencetype_name    RESIDENCY,
                ltp.licensetype_name      LICENSE_TYPE,
                lic.expirationdate        DATE_OF_EXPIRATION
  from odilic_admin.license lic
  inner join odilic_admin.licenseststimeline lst
  on lic.license_id = lst.license_id
  inner join odilic_admin.licenseststype lstp
  on lst.licenseststype_id = lstp.licenseststype_id
  inner join odilic_admin.licensedef ldef
  on lic.licensedef_id = ldef.licensedef_id
  inner join odilic_admin.licensetype ltp
  on ldef.licensetype_id = ltp.licensetype_id
  inner join odilic_admin.residencetype rtp
  on ldef.residencetype_id = rtp.residencetype_id
  inner join odilic_admin.licensingentity le
  on  lic.licensingentity_id = le.licensingentity_id
  inner join odilic_admin.individual ind
  on le.licensingentity_id = ind.licensingentity_id
  inner join odidir_admin.person pers
  on ind.person_id = pers.person_id
  left outer join odidir_admin.person_address_rel par
  on pers.person_id = par.person_id
  left outer join odidir_admin.address adr
  on par.address_id = adr.address_id
  left outer join odidir_admin.address_type atp
  on adr.address_type_id = atp.address_type_id
  left outer join odidir_admin.state_province sp
  on adr.state_province_id = sp.state_province_id
  left outer join
       (select pr.person_id, em.email_id, em.email
          from odidir_admin.person           pr,
               odidir_admin.person_email_rel pe,
               odidir_admin.email            em
         where pr.person_id = pe.person_id
           and pe.email_id = em.email_id
           and email_type_id = 2) eml
  on pers.person_id = eml.person_id
 where 
 ltp.licensetype_id in (:License_type)
 and lstp.licenseststype_name = 'Active'
 and atp.address_type_name = 'Mailing Licensing'
 and (lic.expirationdate >= current_date and
 trunc(lic.expirationdate) = :Expiration_Date)
 and sysdate between lst.periodbegindate and lst.periodenddate
 order by lic.licensenumber

为了获取待处理的应用程序,我需要访问表odilic_admin.licenseappl并过滤掉appststype = 2(pending)的所有许可证。为此,我在最后一个左外连接之前为查询添加了一个连接,并在底部选择了这个参数时添加了一个case。

select distinct pers.person_fname,
                pers.person_mname,
                pers.person_lname,
                le.nationalprovidernumber NPN,
                lic.licensenumber         LICENSE_NUMBER,
                adr.address_line1         ADDRESS1,
                adr.address_line2         ADDRESS2,
                adr.address_line3         ADDRESS3,
                adr.city                  CITY,
                sp.state_province_name    STATE,
                adr.postal_code           ZIP_CODE,
                eml.email,
                rtp.residencetype_name    RESIDENCY,
                ltp.licensetype_name      LICENSE_TYPE,
                lic.expirationdate        DATE_OF_EXPIRATION
  from odilic_admin.license lic
  inner join odilic_admin.licenseststimeline lst
  on lic.license_id = lst.license_id
  inner join odilic_admin.licenseststype lstp
  on lst.licenseststype_id = lstp.licenseststype_id
  inner join odilic_admin.licensedef ldef
  on lic.licensedef_id = ldef.licensedef_id
  inner join odilic_admin.licensetype ltp
  on ldef.licensetype_id = ltp.licensetype_id
  inner join odilic_admin.residencetype rtp
  on ldef.residencetype_id = rtp.residencetype_id
  inner join odilic_admin.licensingentity le
  on  lic.licensingentity_id = le.licensingentity_id
  inner join odilic_admin.individual ind
  on le.licensingentity_id = ind.licensingentity_id
  inner join odidir_admin.person pers
  on ind.person_id = pers.person_id
  left outer join odidir_admin.person_address_rel par
  on pers.person_id = par.person_id
  left outer join odidir_admin.address adr
  on par.address_id = adr.address_id
  left outer join odidir_admin.address_type atp
  on adr.address_type_id = atp.address_type_id
  left outer join odidir_admin.state_province sp
  on adr.state_province_id = sp.state_province_id
  **left outer join odilic_admin.licenseappl appl
  on lic.licensingentity_id = appl.licenseappl_id**
  left outer join
       (select pr.person_id, em.email_id, em.email
          from odidir_admin.person           pr,
               odidir_admin.person_email_rel pe,
               odidir_admin.email            em
         where pr.person_id = pe.person_id
           and pe.email_id = em.email_id
           and email_type_id = 2) eml
  on pers.person_id = eml.person_id
 where 
 ltp.licensetype_id in (:License_type)
 and lstp.licenseststype_name = 'Active'
 and atp.address_type_name = 'Mailing Licensing'
 and (lic.expirationdate >= current_date and
 trunc(lic.expirationdate) = :Expiration_Date)
 and sysdate between lst.periodbegindate and lst.periodenddate
**case :pending when  = yes then appl.applststype_id !=2
end**
 order by lic.licensenumber

除了这种情况,我还尝试使用具有相同结果的IF。这看起来像:

if :Pending = 1
then
 and appl.applststype_id != 2;
end if;

非常感谢任何帮助让我超越这一点,我一定会投票并选择最正确的答案来帮助我解决这个问题。

1 个答案:

答案 0 :(得分:1)

假设您的:pending参数是一个数字,其中值为1表示要排除待处理的许可证,并且您只想排除待处理的许可证应用程序,请尝试添加以下条件代替您现有的case条款:

and (:pending <> 1 or appl.applststype_id !=2)