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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:12:34+00:00 2026-05-21T19:12:34+00:00

I am having to write quite a complicated query at the moment but I

  • 0

I am having to write quite a complicated query at the moment but I am getting stuck. The table structure is as follows

sql linked query

Inquiry is linked to Timelog by a field called Inquiry_ID. My current code which brings back total minutes but for the entire table and not per company. What I am basically after:

Two Columns one for company name (dbo.inquiry.concom) and another for total minutes. The table INQUIRY holds say 100 entries for the same company, I want a row to return the company name once and the total amount of minutes counted for that company name from TIMELOG.LOGMINS

So for example there are 50 entries in dbo.inquiry that have the same company name, I want it to display a distinct company but I need it to total the amount of minutes that is in another table. I am completely lost!

DECLARE @StartDate DATETIME, @EndDate DATETIME
SET              @StartDate = dateadd(mm, - 1, getdate())
SET              @StartDate = dateadd(dd, datepart(dd, getdate()) * - 1, @StartDate)
SET              @EndDate = dateadd(mm, 1, @StartDate)
SELECT DISTINCT TOP 100 PERCENT dbo.INQUIRY.CONCOM, TIMELOG_1.LOGMINS, dbo.INQUIRY.ESCDATE,  dbo.INQUIRY.INQUIRY_ID,
                                                  (SELECT     SUM(LOGMINS) AS Expr1
                                                    FROM          dbo.TIMELOG
                                                    WHERE      dbo.INQUIRY.ESCDATE BETWEEN @Startdate AND @EndDate) AS TOTALMINUTES
                       FROM         dbo.INQUIRY INNER JOIN
                                              dbo.TIMELOG AS TIMELOG_1 ON dbo.INQUIRY.INQUIRY_ID = TIMELOG_1.INQUIRY_ID INNER JOIN
                                              dbo.PROD ON dbo.INQUIRY.PROD_ID = dbo.PROD.PROD_ID INNER JOIN
                                              dbo.CATEGORY ON dbo.PROD.CATEGORY_ID = dbo.CATEGORY.CATEGORY_ID
                       WHERE     dbo.INQUIRY.ESCDATE BETWEEN @Startdate AND @EndDate
                       ORDER BY dbo.INQUIRY.CONCOM

EDIT: The reason the category and product tables are there is because I will need to exclude the count based on whether a product is in a certain category.

  • 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-21T19:12:35+00:00Added an answer on May 21, 2026 at 7:12 pm
    SELECT  i.concom, COALESCE(SUM(t.logmins), 0)
    FROM    inquiry i
    LEFT JOIN
            timelog t
    ON      t.inquiry_id = i.inquiry_id
    GROUP BY
            i.concom
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write quite strange query and i'm having problem with if statement,
For this question, we want to avoid having to write a special query since
I'm having trouble wrapping my head around how to write this query. A hypothetical
I'm having quite some trouble with the WCF Callback mechanism. They sometimes work but
I'm quite new to using the entity framework and I'm having trouble getting my
I'm having trouble getting my python data to write as csvs, either using pylab's
I'm trying to read and write hex but I'm having trouble inputting hex and
Without having to write VBA code, is there a way to maybe write a
I'm having to write a TCP Server for a project at work and I
I am trying to use boost lambda to avoid having to write trivial functors.

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.