1

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

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(待处理)的许可证。为此,我在最后一个左外连接之前向查询添加了一个连接,然后在底部添加了一个案例,说明何时选择了此参数。

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;

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

4

1 回答 1

1

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

and (:pending <> 1 or appl.applststype_id !=2)
于 2013-07-31T12:34:51.583 回答