Getting the error ORA-00920: invalid relational operator
on the following query. What am I doing wrong?
on the following query. What am I doing wrong?
Code:
(select 'Next PM' as pmtype, nvl(pm.location,asset.location) as location, pm.assetnum,
asset.description as assetdescr, pm.pmnum, pm.description, pm.nextdate as pmduedate, pm.jpnum,
jobplan.jpduration as estdur, nvl(jlhrs.elh,0) as estlabhrs, pm.priority as pmpriority, 'PM SCHEDULED' as wonum,
'PM SCHED' as status, pm.nextdate as statusdate, jobplan.laborcode as lead, pm.frequency, pm.frequnit, decode(pm.downtime, 0, 'No', 1, 'Yes') as downtime,
pm.crewid as team, asset.priority as assetpriority, pmseasons.startday, pmseasons.startmonth, pmseasons.endday,
pmseasons.endmonth, (pm.pmcounter + 1) as pmkntr, pm.jpseqinuse, 1 as iterator,
pm.route, pm.siteid
from pm left outer join jobplan
on (pm.jpnum = jobplan.jpnum and pm.siteid = jobplan.siteid)
left outer join asset
on (pm.assetnum = asset.assetnum and pm.siteid = asset.siteid)
left outer join pmseasons
on (pm.pmnum = pmseasons.pmnum and pm.siteid = pmseasons.siteid)
left outer join (select joblabor.jpnum as jpnum, joblabor.siteid as siteid,
sum((nvl(joblabor.laborhrs,0) * nvl(joblabor.quantity,0))) as elh from maximo.joblabor group by joblabor.jpnum,
joblabor.siteid) jlhrs
on (jlhrs.jpnum = pm.jpnum and jlhrs.siteid = pm.siteid)
where + siteidParam and + locParam and + assetParam
and to_date(pm.nextdate) >= to_date('12/1/2010')
and to_date(pm.nextdate) <= to_date('12/31/2010')
)
union
(select 'Projected PM' as pmtype, nvl(pm.location,asset.location) as location, pm.assetnum,
asset.description as assetdescr, pm.pmnum, pm.description,
decode (pm.frequnit,'DAYS', pm.nextdate + pm.frequency * p.x, 'WEEKS', pm.nextdate + pm.frequency * p.x * 7,
'MONTHS', add_months (pm.nextdate, pm.frequency * p.x),
'YEARS', add_months (pm.nextdate,12 * pm.frequency * p.x), null) as pmduedate, pm.jpnum,
jobplan.jpduration as estdur, nvl(jlhrs.elh,0) as estlabhrs, pm.priority as pmpriority, 'PM SCHEDULED' as wonum,
'PM SCHED' as status, pm.nextdate as statusdate, jobplan.laborcode as lead, pm.frequency, pm.frequnit, pm.downtime,
pm.crewid as team, asset.priority as assetpriority, pmseasons.startday, pmseasons.startmonth, pmseasons.endday,
pmseasons.endmonth, (pm.pmcounter + p.x + 1) as pmkntr, pm.jpseqinuse,
p.x + 1 as iterator, pm.route, pm.siteid
from pm left outer join jobplan
on (pm.jpnum = jobplan.jpnum and pm.siteid = jobplan.siteid)
left outer join asset
on (pm.assetnum = asset.assetnum and pm.siteid = asset.siteid)
left outer join pmseasons
on (pm.pmnum = pmseasons.pmnum and pm.siteid = pmseasons.siteid)
left outer join (select joblabor.jpnum as jpnum, joblabor.siteid as siteid,
sum((nvl(joblabor.laborhrs,0) * nvl(joblabor.quantity,0))) as elh from maximo.joblabor group by joblabor.jpnum,
joblabor.siteid) jlhrs
on (jlhrs.jpnum = pm.jpnum and jlhrs.siteid = pm.siteid),(select rownum as x from pm where rownum < 53) p
where + siteidParam and + locParam and + assetParam
and to_date(decode (pm.frequnit,'DAYS', pm.nextdate + pm.frequency * p.x, 'WEEKS', pm.nextdate + pm.frequency * p.x * 7,
'MONTHS', add_months (pm.nextdate, pm.frequency * p.x),
'YEARS', add_months (pm.nextdate,12 * pm.frequency * p.x), null)) >= to_date('12/1/2010')
and to_date(decode (pm.frequnit,'DAYS', pm.nextdate + pm.frequency * p.x, 'WEEKS', pm.nextdate + pm.frequency * p.x * 7,
'MONTHS', add_months (pm.nextdate, pm.frequency * p.x),
'YEARS', add_months (pm.nextdate,12 * pm.frequency * p.x), null)) <= to_date('12/31/2010')
)
order by pmduedate