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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:13:02+00:00 2026-05-22T01:13:02+00:00

I need to find the maximum date for that particular client, that will be

  • 0

I need to find the maximum date for that particular client, that will be treated as latest date (or current date). Then, From there I need to go back 52 weeks to 27 weeks and calculate sum(hours). And 26 Weeks to latest date (or current date) and calculate sum(hours).

 ClientID  StoreID    period      hours
    1       10      2010-04-19  8.04
    1       10      2010-04-20  6.24
    1       10      2010-04-21  8.26
    1       20      2010-04-22  7.94
    1       20      2010-04-23  22.43
    1       20      2010-04-24  22.99
    2       5       2010-12-19  130.67
    2       5       2010-12-26  159.26
    2       5       2011-01-02  113.59
    2       5       2011-01-09  12.66
    2       8       2011-01-16  22.34
    2       8       2011-01-23  11.35

Please let me know how to calculate this in SQL to get ouput ? If you have question ask me.

  • 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-22T01:13:02+00:00Added an answer on May 22, 2026 at 1:13 am

    It’s simplest to just use two queries for this; the first to get the boundary dates, the second to compute the totals. You could roll it all into one query but I don’t think it will make much of a difference.

    DECLARE
        @BeginDate datetime,
        @MidDate datetime
    
    SELECT
        @BeginDate = DATEADD(wk, -52, MAX(period)),
        @MidDate = DATEADD(wk, -25, MAX(period))
    FROM TableName
    WHERE ClientID = @ClientID
    
    SELECT
        SUM(CASE
                WHEN period >= @BeginDate AND period < @MidDate THEN hours
                ELSE 0
            END) AS HoursInFirstHalf,
        SUM(CASE
                WHEN period >= @MidDate THEN hours
                ELSE 0
            END) AS HoursInLastHalf
    FROM TableName
    WHERE ClientID = @ClientID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find/create an application that will create employee web usage reports from
There is an ArrayList which stores integer values. I need to find the maximum
I need to find the on screen size (CGSize) of a string that will
Are there any specific algorithms that will allow me to find the min and
I need to find out the maximum and minimum value in a line by
I need to find the PID of the current running process on a Linux
I need to find the maximum and minimum of an arbitrary C expression which
I need to find maximum and minimum of 8 float values I get. I
I need to find the person who has the maximum items in a list
I have a nxm matrix and I need to find the maximum of sum

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.