Maximo

Maximo

Come for answers, stay for best practices. All we're missing is you.

 View Only
  • 1.  Select non-parent WOs?

    Posted Thu December 10, 2020 04:27 PM
    Edited by System Admin Wed March 22, 2023 11:50 AM

    For non-task WOs:

    I want to select WOs that are either:

    1. Not a parent.
    2. Neither a parent nor a child


    In other words, I want to select non-parent WOs.
    The query would be used in Anywhere to prevent parent WOs from showing up in the Work Technician list.

    Is there a way to write a query like that?

    Thanks.


    #Maximo
    #AssetandFacilitiesManagement


  • 2.  RE: Select non-parent WOs?

    Posted Thu December 10, 2020 06:19 PM
    there are a few fieds that may assist you

    PARENT defines the Parent WO number
    HASCHILDREN is a boolean value that indicated is a WO has a parent

    there are three scenarios

    is a parent: HASCHILDREN=1
    is child: PARENTWO is not null
    neither: HASCHILDREN=0 and PARENTWO is null

    ------------------------------
    Michael Kasteel
    Director
    ISW
    0402830412
    ------------------------------



  • 3.  RE: Select non-parent WOs?

    Posted Thu December 10, 2020 07:33 PM
    Edited by System Admin Wed March 22, 2023 11:45 AM
    Thanks! I think that solved it:

    where
        (parent is not null or (haschildren=0 and parent is null))
        and istask = 0
    



  • 4.  RE: Select non-parent WOs?

    Posted Fri December 11, 2020 12:24 PM
    Hi.

    The HasChildren flag will be set to 1 when a WO has Tasks so I don't think you want to rely on that field if you want to include WOs whose only children are Tasks.

    You said you're using:

    where
        (parent is not null or (haschildren=0 and parent is null))
        and istask = 0

    The first part of that, "Parent IS NOT NULL", will give you all WOs that have a Parent whether or not they have any children.  The second part, "(HasChildren = 0 and Parent IS NULL)" will give you all Top-Level WOs with no Child WOs or Task WOs as children.


    Try:

    WHERE IsTask = 0 and NOT EXISTS (SELECT 1 FROM WorkOrder CWO WHERE CWO.Parent = WO.WONum and CWO.SiteID = WO.SiteID and CWO.IsTask = 0)

    #Maximo
    #AssetandFacilitiesManagement


  • 5.  RE: Select non-parent WOs?

    Posted Fri December 11, 2020 01:06 PM
    Yes, I think you're right.

    I created a WO that is neither a parent to a non-task WO nor a child to a non-task WO. But it does have tasks.

    My query failed to select the WO, but your query succeeded:

    select
        *
    from
        workorder
    where
        wonum = 'WO52153'
        and (istask = 0 and not exists (select 1 from workorder cwo where cwo.parent = workorder.wonum and cwo.siteid = workorder.siteid and cwo.istask = 0))

    1 row selected.

    Thank you!