Maximo Open Forum

 View Only
Expand all | Collapse all

SQL statement turn into Where Clause

  • 1.  SQL statement turn into Where Clause

    Posted 07-26-2023 13:45

    Wondering if anyone can help me insert this select statement as a where clause.  I cannot seem to figure this one out.  The select statement works but I'm stumped as to how to modify the code into a where clause.  Problem is I do not know where to capture all of the select for the where....if that makes sense.  Here is the select.

    select SITEID, ORGID, WONUM, CALNUM, STATUS, CHANGEDATE, NEXT_CHANGEDATE,

           --to_char(CHANGEDATE,'YYYYMMDD HH24:MI:SS') CHANGEDATE,

           --to_char(NEXT_CHANGEDATE,'YYYYMMDD HH24:MI:SS') NEXT_CHANGEDATE,

           ASSET_UTILITIES.CALENDAR_TIME_HOURS

              (ORGID, CALNUM, CHANGEDATE, NEXT_CHANGEDATE, CHANGEDATE, NEXT_CHANGEDATE) STATUS_HOURS

    from (

          select W.WONUM, W.SITEID, W.ORGID, W.ASSETNUM, A.CALNUM, S.STATUS, S.WOSTATUSID,

                 S.CHANGEDATE,

                 nvl(lead(S.CHANGEDATE) over ( order by S.WONUM, S.SITEID, S.CHANGEDATE, S.WOSTATUSID),

                     sysdate) NEXT_CHANGEDATE

            from WORKORDER W

            left join ASSET A

              on W.ASSETNUM = A.ASSETNUM

             and W.SITEID = A.SITEID

            left join WOSTATUS S

              on W.WONUM = S.WONUM

             and W.SITEID = S.SITEID

           where W.WONUM in ( '624671','624672','624673','624674')

             and W.SITEID = 'LEAD'

          ) A

    order by WONUM, SITEID, CHANGEDATE, WOSTATUSID

    Thank you in advance.

    Adam


    #EndUser
    #EverythingMaximo
    #Reporting
    #WorkManagement

    ------------------------------
    Adam Bearden
    GDIT
    ------------------------------


  • 2.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 08:58

    Hi,

    Perhaps I'm oversimplifying your questions, but wouldn't the Maximo where clause be:

     wonum in ( '624671','624672','624673','624674') and siteid = 'LEAD'

    Please let me know if I've misunderstood your intent.

    Stevie



    ------------------------------
    Stevie Holloway
    Tufts University
    ------------------------------



  • 3.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 09:10

    Hi Stevie,

    Thank you for replying.  I appreciate your help.

    Yes, the Maximo where clause would be wonum in('numbers') and siteid = 'LEAD' however, it would not capture any calculations.  Working out of 7.6.2. still and my objective is to create a Result Set lisitng status', ('WAPPR','INPRG','ON HOLD','SCHED','WMATL','MATRCVD','COMP','CLOSE').  Rather the WONUM in('numbers') and siteid = 'LEAD', it will probably go by work group so the customer won't have to look at a thousand+ work orders.  The issue I have is this is the only select statement that works and arranging the majority of the select into a where clause (and capturing all calculations) has been quite challenging. 

    Basically, how can I arrange the entire select into a where? 

    Thanks,

    Adam



    ------------------------------
    Adam Bearden
    GDIT
    ------------------------------



  • 4.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 09:42

    Hi Adam,

    If I correctly understand your requirement, you need a where clause to create a result set query. Then the result set would produce the numbers of work orders by status for a particular group. Is that right?



    ------------------------------
    Stevie Holloway
    Tufts University
    ------------------------------



  • 5.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 10:01

    Stevie,

    Yes sir.  And, the number of days each status was in until the next status change.  This doesn't work as I am still working it but so far I have a where that needs a few things but similarily I would like to have something like this:

    wonum in (select SITEID, ORGID, WONUM, CALNUM, STATUS
           to_char(CHANGEDATE,'YYYYMMDD HH24:MI:SS') CHANGEDATE,
           to_char(NEXT_CHANGEDATE,'YYYYMMDD HH24:MI:SS') NEXT_CHANGEDATE,
           ASSET_UTILITIES.CALENDAR_TIME_HOURS
              (ORGID, CALNUM, CHANGEDATE, NEXT_CHANGEDATE, CHANGEDATE, NEXT_CHANGEDATE)) STATUS_HOURS
    from (
          select W.WONUM, W.SITEID, W.ORGID, W.ASSETNUM, A.CALNUM, S.STATUS,  S.WOSTATUSID, S.CHANGEDATE, 
                    lead(S.CHANGEDATE) over (order by S.WONUM, S.SITEID, S.CHANGEDATE) NEXT_CHANGEDATE
          from WORKORDER W
             left join WOSTATUS S
            on W.WONUM =:S.WONUM
            and W.SITEID =:S.SITEID
            ) A
    and NEXT_CHANGEDATE is not null
    order by WONUM, SITEID, CHANGEDATE ASC

    Adam



    ------------------------------
    Adam Bearden
    GDIT
    ------------------------------



  • 6.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 11:16

    Hi Adam,

    While considering your needs, consider the info in this link.

    https://bportaluri.com/2019/08/tracking-elapsed-time-in-work-order.html

    Stevie



    ------------------------------
    Stevie Holloway
    Tufts University
    ------------------------------



  • 7.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 11:38

    Thank you Stevie.  I am actually using the bportaluri ''Tracking Elapsed Time in Work Order" after our community votes on this.  With a clustered environment and some sites being split, customers opted for voting if any database changes are required.  I have already created the Days In Status attribute and after vote, customers will have the option to pull a report from the Work Order History dialog box.



    ------------------------------
    Adam Bearden
    GDIT
    ------------------------------



  • 8.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 10:03

    To add, I could also use QBR (Ad Hoc) 

    May be a better route for me rather result set.  I'm not sure a KPI will be a good option for what the customer wants.



    ------------------------------
    Adam Bearden
    GDIT
    ------------------------------



  • 9.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 09:04

    Hi Adam,

    In Maximo, "where clause" is that part of SQL statement which is coming after "where".

    The part before "where" is implied from the Maximo application used and the fields in the List view.

    E.g.: in WOTRACK app, if I'm putting into Where clause the string:

    siteid = 'BEDFORD' and status = 'COMP'

    Maximo implies the following SQL statement:

    select wonum, description, location, status, siteid [other-fields-List-View] from workorder where siteid = 'BEDFORD' and status = 'COMP'

    Of course, you won't see "select wonum, description, location, status, siteid [other-fields-here] from workorder" part, but Maximo will consider it as such.

    In the example that you presented there is basically no "where" part.

    And it's not very clear what exactly you want to get with that selection.

    I think that easier would be to define what you really want to get and to start from there.

    Thank you,

    Dragos



    ------------------------------
    Dragos Chitu
    EL
    ------------------------------



  • 10.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 09:17

    Dragos,

    A customer is wanting to track status' ('WAPPR','INPRG','ON HOLD','SCHEDULE','CLOSE','COMP') to look for bottlenecks in his org.  He'd like a Result Set that will list each status on the Result Set and the days in each status.  I'd like the Result Set to look similar to this:

    WONUM

    Asset

    Description

    WAPPR

    SCHED

    INPROGRESS

    ON HOLD

    WMTL

    MATRCD

    COMP

    CLOSED    

    123456

    1XYZ

    Thingamabob

    2

    2

    5

    1

    2

    1

    2456789

    T001358

    Press

    1

    1

    2.12

    0

    25

    2

    2

    1

    With the select, we were able to list each work order by 'WOGROUP' (eliminating each work order number as there would be thousands).  Basically, I'm trying to pull the Work Order History data into a Result Set and all I have to work off of is the select and this select will capture the data we need in SQL.  Problem is, customers do not have access to SQL so a Result Set will have to do.  Hopefully you have a better understanding.

    Thank you for replying,

    Adam



    ------------------------------
    Adam Bearden
    GDIT
    ------------------------------



  • 11.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 10:37

    A BIRT report is out of the question?

    Asking because with a report you could solve it much easier.

    Thank you,

    Dragos



    ------------------------------
    Dragos Chitu
    EL
    ------------------------------



  • 12.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 10:52

    If I am reading this correctly...  Are you are looking for the number of days between work order status changes?

    If so, then I have a very similar report... 

    I use Work Order Status table to look at status changes / dates.

    I use Lead/Lag function to calculate previous status / date to current status / dates.

    LAG(WOSTATUS.CHANGEDATE) OVER ...  as Previous status/date

    WOSTATUS.CHANGEDATE as current status/date

    Current Status/date minus Previous (Lag formula)  status/date

    However, this is in a Birt report, not in QBR or Maximo output.



    ------------------------------
    Charles Smith
    SilverEdge
    ------------------------------



  • 13.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 11:50

    Charles,

    Thank you for your reply.  I could use lead/lag.  We actually have it as part of our select.  I'd have to send this all to our report writers for BIRT.  There are business rules in place that keeps us from performing functions that will create a modification to any xmls or the database, as there are multiple sites that will require vote.  

    I have sent the select to our org guru.  (I was lucky he was willing to take this on)  Hopefully, he can be of help and if so, I will post what he produces.

    Adam



    ------------------------------
    Adam Bearden
    GDIT
    ------------------------------



  • 14.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 13:00

    So QBR seems sufficient as I was able to create a where that will list each status of the work order.  Just can't seem to get the calculations to start.  But, so far; this is looking pretty good.

    Maximum(Status Date):
    Jul 30, 2019, 4:01 PM
    Work Order:
    4639330
    Status:
    CLOSE
    Changed Date:
    2/21/17
    7:06:29 AM
    Maximum(Status Date):
    Jul 26, 2019, 11:59 AM
    Crew
    Status Date
    Changed Date
    Status
    days in status
    MYCREW
    7/26/19
    11:59:46 AM
    7/26/19
    12:00:36 PM
    CLOSE
    0
    MYCREW
    7/26/19
    11:59:46 AM
    7/26/19
    12:00:36 PM
    APPR
    0
    MYCREW
    7/26/19
    11:59:46 AM
    7/26/19
    12:00:36 PM
    ACCEPT
    0
    MYCREW
    7/26/19
    11:59:46 AM
    7/26/19
    12:00:36 PM
    WAPPR
    0
    Crew
    Status Date
    Changed Date
    Status
    days in status
    MYCREW
    7/9/19
    1:38:19 PM
    7/9/19
    1:38:31 PM
    CLOSE
    0
    MYCREW
    7/9/19
    1:38:19 PM
    7/9/19
    1:38:31 PM
    MATRECVD
    0
    MYCREW
    7/9/19
    1:38:19 PM
    7/9/19
    1:38:31 PM
    WMATL
    0
    MYCREW
    7/9/19
    1:38:19 PM
    7/9/19
    1:38:31 PM
    WAPPR
    0
    MYCREW
    7/9/19
    1:38:19 PM
    7/9/19
    1:38:31 PM
    APPR
    0
    MYCREW
    7/9/19
    1:38:19 PM
    7/9/19
    1:38:31 PM
    ACCEPT
    0
    MYCREW
    7/9/19
    1:38:19 PM
    7/9/19
    1:38:31 PM
    INPRG
    0
    Crew
    Status Date
    Changed Date
    Status
    days in status
    MYCREW
    7/12/19
    12:49:45 PM
    7/12/19
    12:50:01 PM
    INPRG
    0
    MYCREW
    7/12/19
    12:49:45 PM
    7/12/19
    12:50:01 PM
    APPR
    0
    MYCREW
    7/12/19
    12:49:45 PM
    7/12/19
    12:50:01 PM
    ACCEPT
    0
    MYCREW
    7/12/19
    12:49:45 PM
    7/12/19
    12:50:01 PM
    WAPPR
    0
    MYCREW
    7/12/19
    12:49:45 PM
    7/12/19
    12:50:01 PM
    CLOSE
    0
    Crew
    Status Date
    Changed Date
    Status
    days in status
    MYCREW
    7/30/19
    4:01:18 PM
    7/30/19
    4:01:23 PM
    ACCEPT
    0
    MYCREW
    7/30/19
    4:01:18 PM
    7/30/19
    4:01:23 PM
    APPR
    0
    MYCREW
    7/30/19
    4:01:18 PM
    7/30/19
    4:01:23 PM
    WAPPR
    0
    MYCREW
    7/30/19
    4:01:18 PM
    7/30/19
    4:01:23 PM
    CLOSE
    0
    Crew
    Status Date
    Changed Date
    Status
    days in status
    MYCREW
    7/22/19
    1:43:37 PM
    7/22/19
    1:43:39 PM
    AWGA
    0
    MYCREW
    7/22/19
    1:43:37 PM
    7/22/19
    1:43:39 PM
    ACCEPT
    0
    MYCREW
    7/22/19
    1:43:37 PM
    7/22/19
    1:43:39 PM
    APPR
    0
    MYCREW
    7/22/19
    1:43:37 PM
    7/22/19
    1:43:39 PM
    WAPPR
    0
    MYCREW
    7/22/19
    1:43:37 PM
    7/22/19
    1:43:39 PM
    CLOSE
    0
    MYCREW
    7/22/19
    1:43:37 PM
    7/22/19
    1:43:39 PM
    APPR
    0


    ------------------------------
    Adam Bearden
    GDIT
    ------------------------------



  • 15.  RE: SQL statement turn into Where Clause

    Posted 07-27-2023 13:04

    I guess my next question would be, in QBR how would I calculate days between status date and changedate?  I can calculate MAXIMUM(statusdate) or MAX(changedate) but doesn't seem to count days between.  I used TIMESTAMPDATEDIFF as an expression however, it doesn't seem to work either.  



    ------------------------------
    Adam Bearden
    GDIT
    ------------------------------



  • 16.  RE: SQL statement turn into Where Clause

    Posted 08-01-2023 11:44

    Hi Adam,

    A little late to the party, but I had created a Chart Report counting the number of WO in each status. Did this using COUNT() then charted using a pie chart for results.  Simple, but maybe will trigger some ideas for you.

    var whereTxt = new String();
    whereTxt = "where " + params["where"];

    whereTxt = whereTxt +" and workorder.status <> 'CLOSE' ";

    var sqlText = new String();

    // Add query to sqlText variable.
    sqlText = "select status, count(1) as total_count from workorder "
    // Include the Maximo where clause
        + whereTxt
         + " group by status order by status"
    ;



    ------------------------------
    NORMA RAMEY
    ------------------------------



  • 17.  RE: SQL statement turn into Where Clause

    Posted 08-04-2023 11:52

    Hi Norma,

    I will absolutely use this as a reference and hopefully it will trigger an idea.  Thank you for your help!

    Adam



    ------------------------------
    A.S. Bearden, GDIT
    'ADAM'
    ------------------------------



  • 18.  RE: SQL statement turn into Where Clause

    Posted 08-07-2023 11:23

    Create a view and use it in your report. You can also add it via DB configuration if you want it to be Maximo aware.



    ------------------------------
    Wes Williams
    Northrop Grumman
    ------------------------------