I have a crystal report which passes a date into an SQL query {?Date}
This worked when crystal is connected using an ODBC connection however on changing it to a 'Oracle Server' connection I get an error:
ORA-01861: literal does not match format string
I have tried removing to_char or to_date (as on research this seems to be the cause of the issue but to no avail)
SELECT
ACTIVE_SEPARATE.WO_NO,
MCH_TYPE,
24 * (to_date(to_char(REAL_F_DATE,'DD-MM-YYYY HH24:MI:SS'), 'DD-MM-YYYY HH24:MI:SS') - to_date(to_char(REQUIRED_START_DATE,'DD-MM-YYYY HH24:MI:SS'), 'DD-MM-YYYY HH24:MI:SS')) as BREAKDOWN_HOURS,
(100 - (((24 * (to_date(to_char(last_day(to_date({?Month}, 'dd-mm-yyyy')),'DD-MM-YYYY'), 'DD-MM-YYYY') - to_date(to_char( trunc(to_date({?Month}, 'dd-mm-yyyy'), 'month'),'DD-MM-YYYY'), 'DD-MM-YYYY'))) + 24) - (24 * (to_date(to_char(REAL_F_DATE,'DD-MM-YYYY HH24:MI:SS'), 'DD-MM-YYYY HH24:MI:SS') - to_date(to_char(REQUIRED_START_DATE,'DD-MM-YYYY HH24:MI:SS'), 'DD-MM-YYYY HH24:MI:SS')))) / ((24 * (to_date(to_char(last_day(to_date({?Month}, 'dd-mm-yyyy')),'DD-MM-YYYY'), 'DD-MM-YYYY') - to_date(to_char( trunc(to_date({?Month}, 'dd-mm-yyyy'), 'month'),'DD-MM-YYYY'), 'DD-MM-YYYY'))) + 24)) AS PERCENTAGE_AVAILABILITY
FROM ACTIVE_SEPARATE
RIGHT JOIN EQUIPMENT_FUNCTIONAL ON EQUIPMENT_FUNCTIONAL.MCH_CODE = (SELECT DISTINCT CASE WHEN MCH_CODE LIKE '%-%' THEN TRIM(SUBSTR(MCH_CODE, 0, INSTR(MCH_CODE, '-')-1)) ELSE MCH_CODE END FROM ACTIVE_SEPARATE ACTIVE_SEPARATE_SUB WHERE ACTIVE_SEPARATE.MCH_CODE = ACTIVE_SEPARATE_SUB.MCH_CODE)
WHERE ERR_CLASS = '001'
AND MCH_TYPE IS NOT NULL
AND (ACTIVE_SEPARATE.REQUIRED_START_DATE BETWEEN
trunc({?Month}, 'MM')
AND
LAST_DAY({?Month}))
The nitty gritty is that the user enters a date (any date). This code will take the date. Work out the total hours in the selected month.
It will also work out the breakdown hours by taking the finish time and the start time away from each other.
Finally it will work out hours in the month - brakedown hours to give us available hours.
select to_char(REAL_F_DATE,'DD-MM-YYYY HH24:MI:SS') from HISTORICAL_SEPARATE;
repeat this out until you are running the whole pieces. – mmmmmpie