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

  • Home
  • SEARCH
  • 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 8189955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:27:29+00:00 2026-06-07T03:27:29+00:00

SQL Server 2000 – 4 tables, 3 columns each. Personal ID (COTA), User (Telegestionador),

  • 0

SQL Server 2000 – 4 tables, 3 columns each. Personal ID (COTA), User (Telegestionador), and an amount-of-work value.

Tables are: Contactados, NC, FQ, OT

Example of one of them.

XAV045  QUIPILDORY    26
XAV045  QUIPILDORY    29
XAV045  QUIPILDORY    21
XAV045  QUIPILDORY    39
XAV052  LOPEZRA       29
XAV052  LOPEZRA       39
XAV052  LOPEZRA       24
XAV052  LOPEZRA       36

What I need is. A result-view with ID, USER and then the fields with the sum of the amount of work grouped by personal id/user. (there are 4 tables, so in the final view I should have 6 columns)

So, first row should be

XAV045,QUIPILDORY, 115, X, Y, Z

Being X, Y, Z the results of SUM() from the other 3 tables.

First try is this:

SELECT     
   dbo.Contactados.COTA, dbo.Contactados.telegestionador, 
   SUM(dbo.Contactados.Total) AS Total, 
   SUM(dbo.OT.Total) AS [Cont-Der], 
   SUM(dbo.FQ.FQ) AS Cerrados, 
   SUM(dbo.NC.Total) AS NC
FROM
   dbo.Contactados 
LEFT OUTER JOIN
   dbo.OT ON dbo.Contactados.COTA = dbo.OT.COTA AND dbo.Contactados.telegestionador = dbo.OT.telegestionador AND dbo.Contactados.FGfin = dbo.OT.FGfin 
LEFT OUTER JOIN
   dbo.FQ ON dbo.Contactados.COTA = dbo.FQ.COTA AND dbo.Contactados.telegestionador = dbo.FQ.telegestionador AND dbo.Contactados.FGfin = dbo.FQ.FGfin 
LEFT OUTER JOIN
   dbo.NC ON dbo.Contactados.COTA = dbo.NC.COTA AND dbo.Contactados.telegestionador = dbo.NC.telegestionador AND dbo.Contactados.FGfin = dbo.NC.FGfin
GROUP BY 
   dbo.Contactados.telegestionador, dbo.Contactados.COTA

It throws wrong results, I know GROUP BY groups the results, not the table rows individually. But I can’t find the proper way to do so.

Any help?

  • 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-07T03:27:31+00:00Added an answer on June 7, 2026 at 3:27 am

    Assuming that all four tables have identical datatypes for the four columns, you can use a union all to list all values, and then sum those as part of a subquery:

    SELECT
    COTA
    ,Telegestionador
    ,SUM(CASE WHEN table_name = 'Contactados' THEN work_value ELSE 0 END) AS Contactados_sum
    ,SUM(CASE WHEN table_name = 'NC' THEN work_value ELSE 0 END) AS nc_sum
    ,SUM(CASE WHEN table_name = 'FQ' THEN work_value ELSE 0 END) AS fq_sum
    ,SUM(CASE WHEN table_name = 'QT' THEN work_value ELSE 0 END) AS qt_sum
    FROM
    (
    SELECT 
    COTA
    ,Telegestionador
    ,work_value
    ,'Contactados' as table_name
    FROM Contactados
    UNION ALL
    SELECT 
    COTA
    ,Telegestionador
    ,work_value
    ,'NC' as table_name
    FROM NC
    UNION ALL
    SELECT 
    COTA
    ,Telegestionador
    ,work_value
    ,'FQ' as table_name
    FROM FQ
    UNION ALL
    SELECT 
    COTA
    ,Telegestionador
    ,work_value
    ,'QT' as table_name
    FROM QT
    ) summary
    GROUP BY
    COTA
    ,Telegestionador
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2000 Table ID Date Value 001 23-02-2009 300 001 24-02-2009 400
Using SQL Server 2000 Master Table ID Date Value 001 23-04-2009 200 001 24-04-2009
work on Sql server 2000. i want to get the current server date and
In SQL Server 2000/2005, Is it possible to force the default value to be
In SQL Server 2000 I noticed that the sysbojects exists in each database. Is
Using SQL Server 2000 I Want to Check the colum value whether it is
Using SQl Server 2000 I have a stored procedure that joins 2 tables and
MS SQL Server 2000 I've realized that in the last couple of tables I've
Using SQL Server 2000 Table PersonID Date 001 11-02-2009 002 11-02-2009 003 11-02-2009 001
Using SQL Server 2000 My Query. SELECT (Format(IIf(CLng(OutTime) > 180000, CDate('18:00:00'), CDate(Format(OutTime, '00:00:00'))) -

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.