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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:21:36+00:00 2026-05-29T09:21:36+00:00

I have a SQL-Sever query that returns the Capacity available to a person on

  • 0

I have a SQL-Sever query that returns the Capacity available to a person on any particular day.
The result is returned against each assignment the person has planned on that particular day.

My problem is that it returns the total capacity for that day on each line of the query’s result.
So when you show all the results for one day for one person, in a linked pivot table in excel (for example), you get the number of records multiplied by the base capacity.

I have written another query that counts the number of assignments per day per person.

I would like to divide the Capacity from the first query, by the number of records returned by the second query, but don’t know how to join the queries together.

This is the query that returns the list of assignments by day with capacity:

SELECT 
  MSP_EpmAssignmentByDay.TimeByDay, 
  MSP_EpmAssignment.ResourceUID, 
  MSP_EpmAssignmentByDay.AssignmentActualWork, 
  MSP_EpmResourceByDay_UserView.Capacity
FROM 
  MSP_EpmAssignment MSP_EpmAssignment,      
  MSP_EpmAssignmentByDay MSP_EpmAssignmentByDay,
  MSP_EpmResourceByDay_UserView
  MSP_EpmResourceByDay_UserView
WHERE   
  MSP_EpmAssignmentByDay.AssignmentUID = MSP_EpmAssignment.AssignmentUID 
  AND MSP_EpmResourceByDay_UserView.TimeByDay = MSP_EpmAssignmentByDay.TimeByDay

This is the query that returns the number of assignments per day per person:

SELECT 
  count(TimeByDay) as DayCount 
FROM 
  MSP_EpmAssignmentByDay_UserView 
  LEFT JOIN MSP_EpmAssignment_UserView
  ON MSP_EpmAssignmentByDay_UserView.AssignmentUID =
     MSP_EpmAssignment_UserView.AssignmentUID
GROUP BY ResourceUID, TimeByDay 

Any help would be greatly appreciated.

Thanks

  • 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-29T09:21:37+00:00Added an answer on May 29, 2026 at 9:21 am

    Assuming the only fields you need are those included in the query, try:

    SELECT 
      MSP_EpmAssignmentByDay.TimeByDay, 
      MSP_EpmAssignment.ResourceUID, 
      SUM(MSP_EpmAssignmentByDay.AssignmentActualWork) TotalWork, 
      MAX(MSP_EpmResourceByDay_UserView.Capacity) Capacity
    FROM 
      MSP_EpmAssignment,      
      MSP_EpmAssignmentByDay,
      MSP_EpmResourceByDay_UserView
    WHERE   
      MSP_EpmAssignmentByDay.AssignmentUID = MSP_EpmAssignment.AssignmentUID 
      AND MSP_EpmResourceByDay_UserView.TimeByDay = MSP_EpmAssignmentByDay.TimeByDay
    GROUP BY
      MSP_EpmAssignmentByDay.TimeByDay, 
      MSP_EpmAssignment.ResourceUID
    

    Alternatively, try changing the summary operation on Capacity in the pivot table to be MAX instead of SUM.

    EDIT: To include a count of records for the same ResourceUID and TimeByDay in the details, try:

    SELECT 
      MSP_EpmAssignmentByDay.TimeByDay, 
      MSP_EpmAssignment.ResourceUID, 
      MSP_EpmAssignmentByDay.AssignmentActualWork, 
      MSP_EpmResourceByDay_UserView.Capacity,
      count(*) over (partition by MSP_EpmAssignmentByDay.TimeByDay,
                                  MSP_EpmAssignment.ResourceUID) DayCount
    FROM 
      MSP_EpmAssignment MSP_EpmAssignment,      
      MSP_EpmAssignmentByDay MSP_EpmAssignmentByDay,
      MSP_EpmResourceByDay_UserView
      MSP_EpmResourceByDay_UserView
    WHERE   
      MSP_EpmAssignmentByDay.AssignmentUID = MSP_EpmAssignment.AssignmentUID 
      AND MSP_EpmResourceByDay_UserView.TimeByDay = MSP_EpmAssignmentByDay.TimeByDay
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very complex Linq to SQL query that returns a result set
I have a Microsoft SQL Server 2008 query that returns data from three tables
So I have a sql server 2005 query that returns results like so: Address
I have a SQL Query running on SQL Server 2008 R2 that returns a
Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
We're using SQL Server 2000 Query Analyser, and one issue we have is that
I have a query that returns data as XML using the for XML Clause
I have a SQL Server query that I need to convert to MySQL. I've
I've got a Sql Table that returns a result as follows: Amount Descrip ----------------------------
I have a SQL query that is quite simply select * from tblOrders where

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.