One of our DBA’s created a custom sql report for one of our customers and I have been tasked with the job of recreating the report using variables added to designer so as to get rid of the custom sql.
I have created an object for Max Survey Date Year and the sql is as follows:
SELECT
to_char(Max(REPORTING_PERIODSurveyDate.FULL_DATE),'YYYY')
FROM
PERIOD REPORTING_PERIODSurveyDate,
SURVEY_HEADER
WHERE
(SURVEY_HEADER.SURVEY_DATE_KEY=REPORTING_PERIODSurveyDate.PERIOD_KEY )
AND (SURVEY_HEADER.SURVEY_DATE_KEY=REPORTING_PERIODSurveyDate.PERIOD_KEY )
I am now trying to modify an existing Current Year Indicator object with the following:
decode(REPORTING_PERIODSurveyDate.CALENDAR_YEAR,@Select(Survey Date\Max Survey Date Year),'1','0')
This is resulting in an oracle error: Not a single-group group function. I realize that it has something to do with the max. Can anyone tell me if there’s another way to do this??
Ok, I’m seeing now that I have to take about 20 steps back (I was hoping to modify just a couple objects but think it will require more than that) and ask another question.
The Survey_Header table has a Survey_Date_Key which is joined to a Date_Key on a generic date table that contains full dates, years, months, quarters, etc.
My goal is to determine the max year in that Survey_Header table using the Survey_Date_Key joined to the Date_Key on the generic date table.
I had tried using the previously mentioned Max Survey Year object, but I now see that it is not working the way it exists now.
You need to add an aggregate function on to calender year or get rid of the max on the other object. The problem has nothing to do with the to_char or it being a measure or dimension, your DB has no idea about measures or dimensions. Your decode has one aggregate object and one non aggregate object. It cant put anything in the group by since the decode contains an aggregate and it cant resolve the query since you dont have a group by.
If you use a case statement it is more clear of what is going on.
case when A then aggregate
else dont aggregate
end
Cant do that, DB cant aggregate 4 rows and then leave 2 rows not aggregated.