I've taken over an XSQL/XML application and I've ran into an odd little work-around by a former employee that I'd like to reduce to a more simple solution. I need a list of months, in order from Current Month all the way back to, say, January 2000. The old solution was:
SELECT
TO_CHAR(SYSDATE), 'fmMonth yyyy') month,
TO_CHAR(ADD_MONTHS(SYSDATE), -1), 'fmMonth yyyy') month,
TO_CHAR(ADD_MONTHS(SYSDATE), -2), 'fmMonth yyyy') month,
TO_CHAR(ADD_MONTHS(SYSDATE), -3), 'fmMonth yyyy') month
etc etc etc.
This worked fine, I don't necessarily need them all under the same field, I just need a list of month. I don't want to have to repeat this code all the way to
TO_CHAR(ADD_MONTHS(SYSDATE), -50), 'fmMonth yyyy') month
Is there a more elegant solution? I suppose I could create a MONTH table with months listed all the way to January 2000, but, of course, I'm just a developer, not a DBA, and creating tables falls outside my 'realm of responsibility. I can keep the existing code, I'm just hoping that, if someone else has to take over this code, they don't laugh at me for not changing it.
Thanks
SELECT
TO_CHAR(SYSDATE), 'fmMonth yyyy') month,
TO_CHAR(ADD_MONTHS(SYSDATE), -1), 'fmMonth yyyy') month,
TO_CHAR(ADD_MONTHS(SYSDATE), -2), 'fmMonth yyyy') month,
TO_CHAR(ADD_MONTHS(SYSDATE), -3), 'fmMonth yyyy') month
etc etc etc.
This worked fine, I don't necessarily need them all under the same field, I just need a list of month. I don't want to have to repeat this code all the way to
TO_CHAR(ADD_MONTHS(SYSDATE), -50), 'fmMonth yyyy') month
Is there a more elegant solution? I suppose I could create a MONTH table with months listed all the way to January 2000, but, of course, I'm just a developer, not a DBA, and creating tables falls outside my 'realm of responsibility. I can keep the existing code, I'm just hoping that, if someone else has to take over this code, they don't laugh at me for not changing it.
Thanks