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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:33:49+00:00 2026-05-15T13:33:49+00:00

Yesterday Thomas helped me a lot by providing exactly the query I wanted .

  • 0

Yesterday Thomas helped me a lot by providing exactly the query I wanted. And now I need a variant of it, and hopes someone can help me out.

I want it to output only one row, namely a max value – but it has to build on the algorithm in the following query:

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
     WHERE     (C2.Country = @Country)
     GROUP BY C.Date, C2.Country OPTION (MAXRECURSION 0)

The output from above will be like:

Date            Country         Allocated testers
06/01/2010      Chile             3
06/02/2010      Chile             4
06/03/2010      Chile             0
06/04/2010      Chile             0
06/05/2010      Chile            19

but what I need right now is

Allocated testers
           19

that is – only one column – one row – the max value itself… (for the (via parameters (that already exists)) selected period of dates and 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-15T13:33:49+00:00Added an answer on May 15, 2026 at 1:33 pm
    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 TOP 1 *
    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
      WHERE
        ( C2.Country = @Country )
      GROUP BY
        C.Date
       ,C2.Country
    OPTION
        ( MAXRECURSION 0 )
        ) lst
        ORDER BY lst.[Allocated testers] DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday i updated my android sdk to api 17. Now the launching of eclipse
Yesterday I was reading a lot about deploying MacOSX applications, but I still have
Yesterday I wanted to add a boolean field to an Oracle table. However, there
Yesterday another user helped out with building a generic function for handling MySQL Queries.
Yesterday I had the need for a matrix type in Python. Apparently, a trivial
Yesterday i implement Log4Net in my application. To use it i need to write
yesterday you had taught me to query record history within a time range here
Yesterday I installed clang 3.1 and g++ 4.7 and tried compiling a project I'm
Yesterday I began to write C# in order to develop usercontrols for Umbraco and
Yesterday I updated to firefox 13 and I notice that this property is not

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.