Sie sind auf Seite 1von 2

Maximo 7.1.x Specification Number: 3010.

03

Maximo Procedure Original Issue Date: January 4, 2010

Title: Using Nested SQL Query Statements Last Revision Date: April 12, 2011

GENERAL: There are times when users will need to find data that is related to other areas or
applications in Maximo. This document explains using nested SQL query statements to aid in the
filter of results inside Maximo.

PROCEDURE: To find records related to extended data you can use the ‘Exists’ statement to filter
your results. For example, a user wants to find all the open work orders, for a given department,
that also have a purchase order associated with it. In this case we need to filter records based on
the following:

• Work orders for just a given site, in this case ‘ACME’


• Work orders not in ‘CAN’, ‘CLOSE’, or ‘MISSED’ status
• Work orders for a specific department
• Work orders that have a purchase order assigned to them
• Purchase orders not in ‘CAN’ or ‘CLOSE’ status

The first three items can be easily found with the following advanced query:

SITEID = ‘ACME’ and GLACCOUNT like ‘%0110%’ and STATUS not in (‘CAN’, ‘CLOSE’, ‘MISSED’)

But what about finding all the work orders that have a PO? That’s where the ‘Exists’ statement
comes in. The ‘Exists’ statement allows a query to look at a group of data records and return
only a subset of those records. The ‘Exists’ statement looks like this:

exists (select * from <secondary table> where (<condition1> and <condition2> and
<condition3> and …))

Each of the conditions are used to reference what information is shared between the primary
table (in our case WORKORDER) and the secondary table (in our case POLINE). Remember the
PO header does not contain any reference to the work order number, so we need to use POLINE
table instead. So our conditions are where a work order number exists in both places and the
SiteID is the same. This makes the Exists statement turn out to be:

exists (select * from POLINE where (REFWO = WORKORDER.WONUM and SITEID = WORKORDER.SITEID))

In our case we want to find all purchase orders that were charged to a work order and from that
list we want to find all the open work orders. The full query would look like this:

SITEID = ‘ACME’ and GLACCOUNT like ‘%0110%’ and STATUS not in (‘CAN’, ‘CLOSE’, ‘MISSED’)
and exists ((select * from POLINE where (REFWO = WORKORDER.WONUM and SITEID =
WORKORDER.SITEID))

If you look at the new query statement we can break it down into 2 main parts:

SITEID = ‘ACME’ and GLACCONT like ‘%0110%′ and STATUS not in (‘CAN’, ‘CLOSE’, ‘MISSED’) and
exists ((select * from POLINE where (REFWO = WORKORDER.WONUM and SITEID =
WORKORDER.SITEID))

What the overall statement is requesting is the return of all the work orders with the following
conditions (SITEID, GLACCOUNT, STATUS) that are also referenced on a purchase order.

Page 1 of 2 Date Printed: 4.19.11


However this isn’t what was originally requested. Originally it was requested to find all all the
active work orders that have an open purchase order. To do this we need to add a nested ‘Exists’
statement to filter out only active purchase orders.

(siteid = ‘ACME’ and glaccount like ‘%0110%’ and status not in (‘CAN’, ‘CLOSE’, ‘MISSED’)
and exists (select * from poline where (refwo=workorder.wonum and siteid=workorder.siteid
and exists (select * from po where (status not in (‘CAN’, ‘CLOSE’) and (ponum=poline.ponum
and siteid=poline.siteid))))))

Now with the additional nested ‘Exists’ statement we have a 3 part query:

• SITEID = ‘LSC’ and GLACCONT like ‘%5060′ and STATUS not in (‘CAN’, ‘CLOSE’, ‘MISSED’)
• exists ((select * from POLINE where (REFWO = WORKORDER.WONUM and SITEID =
WORKORDER.SITEID))
• exists (select * from PO where (STATUS not in (‘CAN’, ‘CLOSE’) and
(PONUM=POLINE.PONUM and SITEID=POLINE.SITEID))

The additional ‘Exists’ statement now returns a list of all purchase orders that are not in the
‘CAN’ or ‘CLOSE’ status. This now gives us a query to find:

1. All work orders at site ‘LSC’, for Dept ’0110′, that are open/active.
2. Of those work orders, show only the ones that are listed on a purchase order.
3. Of those work order, show only the ones on an open purchase order.

Use of the ‘Exists’ statement can now be used for more widespread system monitoring results,
like show all the active work orders that have an Inactive Person assigned as the Lead or
Supervisor:

(status not in (‘CAN’, ‘CLOSE’, ‘MISSED’) and exists (select * from person where
(status=’inactive’ and (personid=WORKORDER.LEAD or personid=WORKORDER.supervisor)
and locationsite=workorder.siteid)))

Page 2 of 2 Date Printed: 4.19.11

Das könnte Ihnen auch gefallen