select 
    target.company_cd 
  , dept.department_name as company_name 
  , target.account_cd 
  , target.term_cd 
  , target.locale_id 
  , target.account_name 
  , target.start_date 
  , target.end_date 
  , target.delete_flag 
  , target.extension_a 
  , target.extension_b 
  , target.extension_c 
  , target.extension_d 
  , target.extension_e 
  , target.extension_f 
  , target.extension_g 
  , target.extension_h 
  , target.extension_i 
  , target.extension_j 
  , target.entry_ts 
  , target.entry_user_cd 
  , target.renew_cnt 
  , target.renew_ts 
  , target.renew_user_cd 
from 
  k30m_account target 
  left join ( 
    select 
        imm_department.company_cd 
      , imm_department.department_set_cd 
      , imm_department.department_cd 
      , imm_department.locale_id 
      , imm_department.start_date 
      , imm_department.end_date 
      , imm_department.department_name 
    from 
      imm_department 
  ) dept 
  on  target.company_cd = dept.company_cd 
  and target.company_cd = dept.department_set_cd 
  and target.company_cd = dept.department_cd 
  and target.locale_id = dept.locale_id 
  /*IF searchCriteriaDate != null*/
  and dept.start_date <= /*searchCriteriaDate*/'2000/01/01' 
  and dept.end_date > /*searchCriteriaDate*/'2000/01/01' 
  /*END*/
/*IF searchType == "search"*/
/*BEGIN*/
where
  /*IF searchCriteriaCompany != null*/
  target.company_cd = /*searchCriteriaCompany*/'searchCriteriaCompany'
  /*END*/
  /*IF searchCriteriaDate != null*/
  and target.start_date <= /*searchCriteriaDate*/'2000/01/01'
  and target.end_date   >  /*searchCriteriaDate*/'2000/01/01'
  /*END*/
  /*IF searchWithDisabled != null*/
  and target.delete_flag = /*searchWithDisabled*/'searchWithDisabled'
  /*END*/
  /*IF searchCriteriaLocale != null*/
  and target.locale_id = /*searchCriteriaLocale*/'searchCriteriaLocale'
  /*END*/
  /*IF searchCriteriaKeyword != null*/
  and (
    target.account_cd           like /*searchCriteriaKeyword*/'%' ESCAPE '$'
    or target.account_name      like /*searchCriteriaKeyword*/'%' ESCAPE '$'
  )
  /*END*/
/*END*/
/*IF orderBy != null*/
order by /*$orderBy*/account_cd
/*END*/
/*END*/
/*IF searchType == "select"*/
/*BEGIN*/
where
  /*IF accountCd != null*/
  target.account_cd = /*accountCd*/'accountCd'
  /*END*/
  /*IF companyCd != null*/
  and target.company_cd = /*companyCd*/'companyCd'
  /*END*/
  /*IF termCd != null*/
  and target.term_cd = /*termCd*/'termCd'
  /*END*/
/*END*/
order by account_cd
/*END*/
/*IF searchType == "term"*/
/*BEGIN*/
where
  /*IF accountCd != null*/
  target.account_cd = /*accountCd*/'accountCd'
  /*END*/
  /*IF companyCd != null*/
  and target.company_cd = /*companyCd*/'companyCd'
  /*END*/
  /*IF localeId != null*/
  and target.locale_id = /*localeId*/'localeId'
  /*END*/
/*END*/
order by account_cd, start_date
/*END*/
/*IF searchType == "master"*/
/*BEGIN*/
where
  /*IF accountCd != null*/
  target.account_cd = /*accountCd*/'accountCd'
  /*END*/
  /*IF searchCriteriaCompany != null*/
  and target.company_cd = /*searchCriteriaCompany*/'searchCriteriaCompany'
  /*END*/
  /*IF searchCriteriaDate != null*/
  and target.start_date <= /*searchCriteriaDate*/'2000/01/01'
  and target.end_date    > /*searchCriteriaDate*/'2000/01/01'
  /*END*/
  /*IF deleteFlag != null*/
  and target.delete_flag = /*deleteFlag*/'deleteFlag'
  /*END*/
  /*IF searchCriteriaLocale != null*/
  and target.locale_id = /*searchCriteriaLocale*/'searchCriteriaLocale'
  /*END*/
  /*IF searchCriteriaKeyword != null*/
  and (
    target.account_cd           like /*searchCriteriaKeyword*/'%' ESCAPE '$'
    or target.account_name      like /*searchCriteriaKeyword*/'%' ESCAPE '$'
  )
  /*END*/ 
/*END*/
order by account_cd
/*END*/
/*IF searchType == "export"*/
/*BEGIN*/
where
  /*IF searchCriteriaCompany != null*/
  target.company_cd = /*searchCriteriaCompany*/'searchCriteriaCompany'
  /*END*/
  /*IF targetDate != null*/
  and target.start_date <= /*targetDate*/'2000/01/01'
  and target.end_date    > /*targetDate*/'2000/01/01'
  /*END*/
  /*IF renewTs != null*/
  and target.renew_ts >= /*renewTs*/'2000/01/01'
  /*END*/
/*END*/
order by account_cd, start_date, locale_id
/*END*/