Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6808603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:58:35+00:00 2026-05-26T19:58:35+00:00

I’m looking for the correct way to structure the query for a view in

  • 0

I’m looking for the correct way to structure the query for a view in order to include some totaling, etc. on the DB side (the view will be used by reporting systems).

Relevant Data Structure

+---------+      +---------+
|WORKORDER|      |WPLABOR  |
|---------|      |---------|
|WONUM    |+---->|WONUM    |
|...      |  +   |LABORHRS |
+---------+  |   |RATE     |
             |   +---------+
             |
             |   +---------+
             |   |WPITEM   |
             |   |---------|
             +-->|WONUM    |
             |   |ITEMQTY  |
             |   |UNITCOST |
             |   +---------+
             |
             |   +----------------+
             |   |LONGDESCRIPTION |
             |   |----------------|
             +-->|LDKEY           |
                 |LDTEXT          |
                 +----------------+

Goal

I would like to return the following:

  • Various items from Workorder
  • The sum of all labor costs (sum of each laborhrs*rate)
  • The sum of all items (sum of each itemqty*unitcost)
  • The LDText CLOB

I’m to the point where I have the relevant information displayed in the query, but am struggling with the totaling of the labor and item costs.

Query So Far

 SELECT 
    WORKORDER.WONUM, 
    WORKORDER.ACTLABHRS, 
    WORKORDER.LOCATION, 
    WORKORDER.STATUS, 
    WORKORDER.WO7,          -- Requester
    WORKORDER.WO8,          -- Extension
    WORKORDER.WO9,          -- Location
    WORKORDER.LEADCRAFT, 
    WORKORDER.WO11,         -- Extension
    WORKORDER.GLACCOUNT, 
    WORKORDER.WO10,         -- Contact
    WORKORDER.DESCRIPTION,  -- Short description
    WORKORDER.WO6,          -- Plant rearrangement (YORN / boolean value)
    LONGDESCRIPTION.LDTEXT,
    WPLABOR.LABORHRS,
    WPLABOR.RATE,
    WPITEM.ITEMQTY,
    WPITEM.UNITCOST
  FROM   
    MAXIMO.WORKORDER
  LEFT OUTER JOIN 
    MAXIMO.LONGDESCRIPTION
      ON WORKORDER.WONUM = CAST(LONGDESCRIPTION.LDKEY as varchar(22))

  LEFT OUTER JOIN
    MAXIMO.WPLABOR
      ON WORKORDER.WONUM = WPLABOR.WONUM

  LEFT OUTER JOIN
    MAXIMO.WPITEM
      ON WORKORDER.WONUM = WPITEM.WONUM

  WHERE  
    LONGDESCRIPTION.LDOWNERTABLE='WORKORDER' AND
    LONGDESCRIPTION.LDOWNERCOL = 'DESCRIPTION';

Thanks for any help you can give!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:58:36+00:00Added an answer on May 26, 2026 at 7:58 pm

    When you join tables together, you get one row for each possible combination. So if one work order has 3 labor rows and 4 item rows, a join of the three tables returns 12 rows.

    One way to avoid that is to group by workorder in a subquery:

    SELECT  WORKORDER.WONUM
    ,       LONGDESCRIPTION.LDTEXT
    ,       ... other columns ...
    ,       Labor.LaborCost
    ,       Item.ItemCost
    FROM    MAXIMO.WORKORDER
    LEFT JOIN 
            MAXIMO.LONGDESCRIPTION
    ON      WORKORDER.WONUM = CAST(LONGDESCRIPTION.LDKEY as varchar(22))
    LEFT JOIN
            (
            SELECT  WONUM
            ,       SUM(WPLABOR.LABORHRS * WPLABOR.RATE) as LaborCost
            FROM    MAXIMO.WPLABOR
            GROUP BY
                    WOWNUM
            ) Labor        
    ON      WORKORDER.WONUM = Labor.WONUM
    LEFT JOIN
            (
            SELECT  WONUM
            ,       SUM(WPITEM.ITEMQTY * WPITEM.UNITCOST) as ItemCost
            FROM    MAXIMO.WPITEM
            GROUP BY
                    WOWNUM
            ) Item
    ON      WORKORDER.WONUM = Item.WONUM
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I need a function that will clean a strings' special characters. I do NOT
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.