案例陈述语法

时间:2014-09-03 18:00:29

标签: sql oracle11g

我使用的表格按会计年度和会计期间折旧。我试图让折旧金额根据会计年度和会计期间分为2个不同的列。我试图用嵌套的case语句来做这件事;我确定不正确,因为我收到了 ORA-00905消息。我对Oracle SQL比较陌生,这也是我的问题所在。以下是我的代码。任何建议/更正将不胜感激帮助...

SELECT 
pdr.DEPTID as DEPTID, 
pdr.ASSET_ID as ASSET_NO,
pa.descr as DESCRIPTION,
pdr.ACCOUNT_AD as AD_ACCT, 
pdl.ACCOUNT as DE_ACCT,
pdr.DEPR as AMT_DEPR,
pdl.JOURNAL_ID as JRNL_ID,
pdl.JOURNAL_DATE as JRNL_DT,
pdr.FISCAL_YEAR as FY,
pdr.ACCOUNTING_PERIOD as AP,

CASE 
  WHEN pdr.FISCAL_YEAR = 2014 THEN
    WHEN pdr.ACCOUNTING_PERIOD = 11 THEN pdr.DEPR 
    END AS CURR_MONTH,

CASE  
  WHEN pdr.FISCAL_YEAR <> 2014  
    WHEN pdr.ACCOUNTING_PERIOD <> 11 THEN pdr.DEPR 
    END AS PRIOR_MONTH

FROM PS_DEPR_RPT pdr

INNER JOIN PS_DIST_LN pdl 
ON pdl.BOOK = pdr.BOOK
AND pdl.BUSINESS_UNIT = pdr.BUSINESS_UNIT
AND pdl.FISCAL_YEAR = pdr.FISCAL_YEAR
AND pdl.ACCOUNTING_PERIOD = pdr.ACCOUNTING_PERIOD
AND pdl.ASSET_ID = pdr.ASSET_ID
AND pdl.CF_SEQNO = pdr.CF_SEQNO

INNER JOIN PS_ASSET pa 
ON pa.ASSET_ID = pdl.ASSET_ID
AND pa.BUSINESS_UNIT = pdl.BUSINESS_UNIT

WHERE
pdr.BUSINESS_UNIT='A0465'
AND pdr.BOOK='PERFORM' 
AND ((pdr.FISCAL_YEAR = 2014 AND pdr.ACCOUNTING_PERIOD = 11) OR (pdr.FISCAL_YEAR = 2014 AND pdr.ACCOUNTING_PERIOD = 10)) ;

0 个答案:

没有答案