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 8655775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:07:18+00:00 2026-06-12T15:07:18+00:00

I’m a CTO for a small manufacturing firm, obviously doing some very hands on

  • 0

I’m a CTO for a small manufacturing firm, obviously doing some very hands on stuff and am grateful to experts out there providing their time to people less experienced.

I’m trying to construct a query for SQL Server to aggregate time for each machine in a manufacturing process.

The results I get look something like:

InvoiceID Min DateIn      MachineName  MachineID
17993     12  2012-09-28  Beam Saw     1
17993     26  2012-09-28  Beam Saw     1
17993     17  2012-10-02  Edge Banding 3
17993     21  2012-10-02  Skipper      4
17993     23  2012-10-03  Shipping     5

etc for next invoice.

My code:

SELECT i.InvoiceID
    ,SUM(DATEPART(Minute,(wf.DateTimeOut - wf.DateTimeIn))) AS [Min]
    ,CAST(wf.DateTimeIn AS DATE) AS [DateIn]
    ,m.MachineName
    ,wf.MachineID
FROM Workflow wf 
    JOIN
        InvoicesPerJobPeriod ipjp
        ON
        ipjp.Workflowid = wf.ID
    JOIN Machines m
        ON 
        m.MachineID = wf.MachineID
    JOIN
        Invoices i
        ON ipjp.InvoiceID = i.InvoiceID
WHERE (i.InActive = '0') 
GROUP BY i.InvoiceID, m.MachineName, wf.MachineID, wf.DateTimeIn
ORDER BY i.InvoiceID, wf.MachineID

I don’t understand why the grouping shows multiple records for the Beam Saw. Ideally, there should be one record per machine, per invoice. The Datetimein is usually going to be the same day, but I need to display it, just in case a manufacturing step spans days. In that case I would reasonable to have multiple records for a machine.

Thank you so much for your help. It’s greatly appreciated.

Cliff

  • 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-06-12T15:07:19+00:00Added an answer on June 12, 2026 at 3:07 pm

    If wf.DateTimeIn is different at all (in either the date or the time components) for two different Beam Saw records, they will generate separate lines in the GROUP BY clause, even though your non-aggregated usage in the SELECT statement is only referring to the date portion.

    If what you want is to group by the date portion of DateTimeIn only, you should write something like this:

    GROUP BY i.InvoiceID, m.MachineName, wf.MachineID, CAST(wf.DateTimeIn AS DATE)
    

    This will ensure that any number of Beam Saw records that otherwise match and are entered on the same date will be grouped together into a single row.

    However, this may change the semantics of your aggregate statement, so you’ll need to verify the query works as you desire after you make this change.

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

Sidebar

Related Questions

I know there's a lot of other questions out there that deal with this
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 have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.