WITH corp AS (
    SELECT
        corp_code -- 公司编码
         ,corp_name  -- 公司名称
    FROM dwr.dim_corp
    WHERE corp_type = '实体'
      AND	(parent_corp_code LIKE '02%' OR corp_code = '0301')
        ${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")}
)
SELECT
 bill_date          -- 制单日期
,bill_emp_code      -- 制单人工号
,corp_code          -- 公司编码
,acnt_book_name     -- 主体账簿
,vouch_type         -- 凭证类别
,vouch_code         -- 凭证号
,acnt_year          -- 账期年度
,acnt_mon           -- 账期月度
,main_abstract      -- 主表摘要
,entry_code         -- 分录号
,sub_abstract       -- 子表摘要
,subject_code       -- 科目编码
,subject_name       -- 科目名称
,subject_full_name  -- 科目全称
,aux_content        -- 辅助核算
,debit_amt          -- 借方金额
,credit_amt         -- 贷方金额
,src_bill_codes     -- 来源单据号
,acnt_date          -- 记账日期
FROM dwi.dwi_fim_voucher WHERE src_bill_codes = 'BR08020240302938'
where subject_code like '6601%'
and corp_code in(SELECT corp_code FROM corp)
-- AND acnt_year = '${YEAR(sQueryDate)}'
-- AND acnt_mon <= '${FORMAT(sQueryDate,"MM")}'
${switch(sCalcType
,"m","AND concat(acnt_year,'-',acnt_mon) <= '" + sQueryDate + "' AND concat(acnt_year,'-',acnt_mon) >= '" + sQueryStartDate + "'"
,"y","AND concat(acnt_year,'-',acnt_mon) <= '" + sQueryDate + "' AND concat(acnt_year,'-',acnt_mon) >= '" + sQueryStartDate + "'"
)}
${nvl(switch(sSubject
,"0000","AND subject_code like '6601%' AND (subject_code not like '660114%'
             AND subject_code not like '660127%'
             AND subject_code NOT like '660150%'
             AND subject_code NOT like '660115%'
             AND subject_code NOT like '660117%'
             AND subject_code NOT like '660136%'
             AND subject_code NOT like '660130%'
             AND subject_code NOT like '660125%'
             AND subject_code NOT like '660167%'
             AND subject_code NOT like '660121%'
             AND subject_code NOT like '660164%'
            )"
,"660114,660127","AND (subject_code like '660114%' or subject_code like '660127%')")
,"and subject_code like '" + sSubject +"%'")}
