当前位置: 代码迷 >> PB >> 检索条件!该如何解决
  详细解决方案

检索条件!该如何解决

热度:22   发布时间:2016-04-29 07:43:18.0
检索条件!
检索病历操作,首先每个病历都有一个叫ICD10_CODE的编码 ICD10_CODE在表1中 随访日期在表2中 出院时间在表3中
条件一:ICD10_CODE在C00.0--C97.0 与 D32.0--D33.9之间的病历 且出院时间(out_time)大于6个月
条件二:距离上次随访日期(visit_date)的时间大于6个月 
这样的检索条件在PB中咋写
------解决方案--------------------
select a.* from 表1 a
where ((a.ICD10_CODE between 'C00.0' and 'C97.0') or (a.ICD10_CODE between 'D32.0' and 'D33.9')) and not exists(select 1 from 表2 b where b.ICD10_CODE = a.ICD10_CODE and datediff(mm, b.visit_date, getdate()) < 6 )
and exists(select 1 from 表3 c where c.ICD10_CODE = a.ICD10_CODE and datediff(mm, c.out_time, getdate()) >= 6 )



你可以用dw来实现,为dw添加六个参数
code1 string
code2 string
code3 string
code4 string
vm number
om number
然后dw的sql语句写成:
select a.* from 表1 a
where ((a.ICD10_CODE between :code1 and :code2) or (a.ICD10_CODE between :code3 and :code4)) and not exists(select 1 from 表2 b where b.ICD10_CODE = a.ICD10_CODE and datediff(mm, b.visit_date, getdate()) < :vm )
and exists(select 1 from 表3 c where c.ICD10_CODE = a.ICD10_CODE and datediff(mm, c.out_time, getdate()) >= :om )


这样一来在button的clicked事件中,可以写:
dw_1.retrieve(ls_code1, ls_code2, ls_code3, ls_code4, li_vm, li_om)
------解决方案--------------------
帮你搜了一下,这是别人写的,oracle的自定义函数datediff

create   or   replace   function   
--   --   works   in   roughly   the   same   way   as   sybase   datsdiff 
--   call   would   be   eg.   datediff( 'month ',date1,date2) 
--   p_what   would   be   'HOUR ',   'DAY ', 'MONTH '   OR   'QUARTER ' 
datediff(   p_what   in   varchar2, 
                    p_d1       in   date, 
                  p_d2       in   date   )   return   number 
as 
l_result         number; 
begin 
        l_result:=null; 
        if   (upper(p_what)   =   'HOUR ')   then 
            l_result:=((p_d2-p_d1)*24); 
        end   if; 
        if   (upper(p_what)   =   'DAY ')   then 
  相关解决方案