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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:45:11+00:00 2026-05-27T00:45:11+00:00

I am having difficulty with this. This query worked fine in calculating the sums

  • 0

I am having difficulty with this. This query worked fine in calculating the sums until I put the first inner join in. In the table tbl_companies there are multiple entries per company, for example the table could look like this:

priority      company     externalip
1             bla         9.9.9.9
1             bla         3.3.3.3
1             company2    3.56.6.6

In the below query the sum (that calculates As TotalWithoutNew and TotalAllId is doubling when there is more than one entry for the company, and tripling if there is three etc. What I want it to do is simply bring back the priority from the table tbl_companies

SELECT b.company, 
       b.priority, 
       i.concom, 
       Coalesce (SUM(CASE 
                       WHEN c.category_id = '30' THEN 0 
                       ELSE t.logmins 
                     END), 0)       AS totalwithoutnew, 
       Coalesce (SUM(t.logmins), 0) AS totalallid 
FROM   helpdesk3.dbo.inquiry AS i 
       INNER JOIN [Check].[dbo].[tbl_companies] AS b 
         ON i.concom = b.company COLLATE sql_latin1_general_cp1_ci_as 
       INNER JOIN timelog AS t 
         ON t.inquiry_id = i.inquiry_id 
       INNER JOIN prod AS p 
         ON i.prod_id = p.prod_id 
       INNER JOIN category AS c 
         ON p.category_id = c.category_id 
WHERE  ( Datepart(yyyy, escdate) = 2011 ) 
GROUP  BY i.concom, 
          b.company, 
          b.priority 
ORDER  BY totalwithoutnew DESC, 
          b.priority DESC    
  • 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-27T00:45:12+00:00Added an answer on May 27, 2026 at 12:45 am

    You should split the query to avoid multiple results from tbl_companies.

    select distinct b.company, 
           b.priority, 
           x.concom, 
           x.totalwithoutnew, 
           x.totalallid 
    FROM    (
                SELECT i.concom, 
                       Coalesce (SUM(CASE 
                                       WHEN c.category_id = '30' THEN 0 
                                       ELSE t.logmins 
                                     END), 0)       AS totalwithoutnew, 
                       Coalesce (SUM(t.logmins), 0) AS totalallid 
                FROM   helpdesk3.dbo.inquiry AS i 
                       INNER JOIN timelog AS t 
                         ON t.inquiry_id = i.inquiry_id 
                       INNER JOIN prod AS p 
                         ON i.prod_id = p.prod_id 
                       INNER JOIN category AS c 
                         ON p.category_id = c.category_id 
                WHERE  ( Datepart(yyyy, escdate) = 2011 ) 
                GROUP  BY i.concom 
                ) x
    INNER JOIN [Check].[dbo].[tbl_companies] AS b 
              ON x.concom = b.company COLLATE sql_latin1_general_cp1_ci_as 
    
    ORDER  BY x.totalwithoutnew DESC, 
              b.priority DESC  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having difficulty representing this query (which works on the database directly) as a
This is a simple sort of crosstab query. I am having difficulty transferring my
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and
I'm having difficulty doing this seemingly simple task. I want to load XML files
I'm having difficulty searching for this. How would I define an element in an
This concerns iPhoneOS-sdk-3.2 I am having difficulty changing the border color of a grouped
I'm trying to use this library (which looks very nice) but I'm having difficulty
I have been trying to tackle this problem , but I am having difficulty
I'm studying for an exam and I'm having difficulty with a concept. This is
I am having a bit of difficulty with this current code I have set

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.