Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Non constant not allowed for pivot unpivot values Error

ChoMan23Dec 27 2011 — edited Dec 27 2011
I am receiving the following error in my PIVOT

Non constant not allowed for pivot unpivot values

I know it is related to the IN Clause. Is there a way not to have constant values there. I need this to be dynamic. Here is my code:

WITH MainCampus AS
(
SELECT EXTRACT(Year FROM kmv."LAST_DAY(EDW.HAR.ADMIT_DT)") as "Admit_Dt"
,kmv."COUNT(EDW.HAR.HAR_ID)" as "Total_HarId"
,kc.KPI_DESC
FROM EDW.KPI_FACT_DEPT_MV kmv JOIN EDW.KPI_CD kc ON (kmv.KPI_CD = kc.KPI_CD)
JOIN EDW.PT_CLASS pc ON (kmv.PT_CLASS = pc.pt_class)
LEFT JOIN EDW.DEPT d ON (kmv.DEPT_ID = d.DEPT_ID)
JOIN EDW.DEPT_SVC_TYPE dt ON (kmv.DEPT_SVC_TYPE = dt.DEPT_SVC_TYPE)
WHERE kc.KPI_DESC = 'ADMITS'
AND d.DEPT_ID<>('4012')
AND d.DEPT_ID<>('4014')
AND d.DEPT_ID<>('4019')
AND d.DEPT_ID<>('4023')
AND d.DEPT_ID<>('4025')
AND pc.PT_CLASS_DESC IN ('INPATIENT','LOOP ORGAN PROCUREMENT')
)

SELECT *
FROM MainCampus
PIVOT (
SUM("Total_HarId")
FOR "Admit_Dt"
IN ('2002','2003','2004')
);


I would like to be able to dynamically have the PIVOT only look 10 years back from today's current year. Is this possible? Thank you.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 24 2012
Added on Dec 27 2011
8 comments
1,764 views