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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:30:31+00:00 2026-05-16T06:30:31+00:00

I have two great tables that I would like to use as foundation for

  • 0

I have two great tables that I would like to use as foundation for an even greater third table!

The output depends on date interval, like 09/01/2010 – 09/03/2010

Example of Output from TABLE A – – (ALLOCATED Testers)

Date            Country        Allocated testers
09/01/2010      Nigeria           0
09/02/2010      Nigeria           1
09/03/2010      Nigeria         134

09/01/2010      China             2
09/02/2010      China             0
09/03/2010      China            14

09/01/2010      Chile             3
09/02/2010      Chile             4
09/03/2010      Chile             0

*************

Example of Output from TABLE B – – (ABSENT Testers)

Date            Country        Absent testers
09/01/2010      Nigeria           0
09/02/2010      Nigeria           7
09/03/2010      Nigeria           0

09/01/2010      China             2
09/02/2010      China             0
09/03/2010      China             0

09/01/2010      Chile             1
09/02/2010      Chile             0
09/03/2010      Chile             0

*************

Example of WANTED output from TABLE C (ALLOCATED AND ABSENT Testers)

Date            Country        Allocated testers    Absent testers
09/01/2010      Nigeria           0                 0
09/02/2010      Nigeria           1                 7
09/03/2010      Nigeria         134                 0

09/01/2010      China             2                 2
09/02/2010      China             0                 0
09/03/2010      China            14                 0

09/01/2010      Chile             3                 2
09/02/2010      Chile             4                 0
09/03/2010      Chile             0                 0

And here is some SQL code generating the above shown output… (yes, they work)

TABLE A

WITH Calendar AS (SELECT     CAST(@StartDate AS datetime) AS Date
     UNION ALL
     SELECT     DATEADD(d, 1, Date) AS Expr1
     FROM         Calendar AS Calendar_1
     WHERE     (DATEADD(d, 1, Date) < @EndDate))
    SELECT     C.Date, C2.Country, COALESCE (SUM(R.[Amount of people per day needed]), 0) AS [Allocated testers]
     FROM         Calendar AS C CROSS JOIN
                            Country AS C2 LEFT OUTER JOIN
                            Requests AS R ON C.Date BETWEEN R.[Start date] AND R.[End date] AND R.CountryID = C2.CountryID
     GROUP BY C.Date, C2.Country OPTION (MAXRECURSION 0)

TABLE B

WITH Calendar AS (SELECT     CAST(@StartDate AS datetime) AS Date
     UNION ALL
     SELECT     DATEADD(d, 1, Date) AS Expr1
     FROM         Calendar AS Calendar_1
     WHERE     (DATEADD(d, 1, Date) < @EndDate))
    SELECT     C.Date, C2.Country, COALESCE (COUNT(PA.PeopleID), 0) AS [Absent testers]
     FROM         Calendar AS C CROSS JOIN
                            Country AS C2 INNER JOIN
                            Roles AS R INNER JOIN
                            People AS P ON R.RolesID = P.RolesID ON C2.CountryID = P.CountryID LEFT OUTER JOIN
                            PeoplesAbsence AS PA ON C.Date BETWEEN PA.StartDate AND PA.EndDate AND P.PeopleID = PA.PeopleID
     WHERE     (R.Role = 'Tester')
     GROUP BY C.Date, C2.Country OPTION (MAXRECURSION 0)

TABLE C is the one I need help to create 🙂

NOTE: I would like to see some kind of example code, to get started!

NOTE ALSO: I don´t want to solve this with Views in SQL Server, because it just doesn´t work… – I need that 3:rd table 😉


SOLVED! Got the solution from tdammers (thanks!), and this is how it looks when implemented:

WITH Calendar AS (SELECT     CAST(@StartDate AS datetime) AS Date
UNION ALL
SELECT
    DATEADD(d, 1, Date) AS Expr1
FROM
    Calendar AS Calendar_1
WHERE
    (DATEADD(d, 1, Date) < @EndDate))


SELECT a.Date, a.Country, a.[Allocated testers], b.[Absent testers] FROM ( SELECT
    C.Date, C2.Country, COALESCE (SUM(R.[Amount of people per day needed]), 0) AS [Allocated testers]
FROM
    Calendar AS C
CROSS JOIN
    Country AS C2
LEFT OUTER JOIN
    Requests AS R 
    ON
        C.Date BETWEEN R.[Start date] AND R.[End date] AND R.CountryID = C2.CountryID
GROUP BY
    C.Date, C2.Country ) as a LEFT OUTER JOIN ( SELECT     C.Date, C2.Country, COALESCE (COUNT(PA.PeopleID), 0) AS [Absent testers]
     FROM         Calendar AS C CROSS JOIN
                            Country AS C2 INNER JOIN
                            Roles AS R INNER JOIN
                            People AS P ON R.RolesID = P.RolesID ON C2.CountryID = P.CountryID LEFT OUTER JOIN
                            PeoplesAbsence AS PA ON C.Date BETWEEN PA.StartDate AND PA.EndDate AND P.PeopleID = PA.PeopleID
     WHERE     (R.Role = 'Tester')
     GROUP BY C.Date, C2.Country ) as b ON a.date = b.date AND a.country = b.country
  • 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-16T06:30:31+00:00Added an answer on May 16, 2026 at 6:30 am

    Table C shouldn’t be a table, but rather a view.

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

Sidebar

Related Questions

I have a query that is joining two tables. I would like to be
I have an existing table that I'd like to use for a Rails application.
I have a series of two chained selects using ajax that work great. I
using mysql and php, I have two tables, I'm french so the table names
I have two tables post Table post_id post_name post_summary date post_reply Table parent_id post_id
To illustrate, assume that I have two tables as follows: VehicleID Name 1 Chuck
I've found that I can have two tables and create a fast refresh on
I would like to create a interface that I can use with different types.
I have made a lookup table that allows you to blend two single-byte channels
I have two tables images2 and image_data So the goal is to have 1

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.