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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:34:22+00:00 2026-05-16T16:34:22+00:00

I have a table set up like this Project Category Date Hours Proj1 test

  • 0

I have a table set up like this

Project   Category   Date       Hours
Proj1     test       8/2/2010   2
Proj1     test       8/3/2010   8
Proj1     test       8/4/2010   4
Proj1     test       8/5/2010   3
Proj1     test       8/6/2010   5

I want to develop a query where you can input a saturday(Week Ending) date and get a result like this

WeekEnding Project Category  SunHrs MonHrs TuesHrs WedHrs ThuHrs FriHrs SatHrs  
8/7/2010   Proj1   test      0      2      8       4      3      5      0

Thank you

  • 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-16T16:34:23+00:00Added an answer on May 16, 2026 at 4:34 pm

    Here’s one way. It looks kind of kludgey, but then pivots always look that way to me.

    DECLARE @Saturday datetime
    
    SET @Saturday = 'Aug 7, 2010'
    
    SELECT
       @Saturday       WeekEnding
      ,Project
      ,Category
      ,isnull([1], 0)  SunHrs
      ,isnull([2], 0)  MonHrs
      ,isnull([3], 0)  TueHrs
      ,isnull([4], 0)  WedHrs
      ,isnull([5], 0)  ThuHrs
      ,isnull([6], 0)  FriHrs
      ,isnull([7], 0)  SatHrs
     from (select Project, Category, Datepart(dw, Date) DOW, Hours
            from MyTable
            --  Fixed bug from -7 to -6
            where Date between dateadd(dd, /*-7*/ -6, @Saturday) and @Saturday) Source
      pivot (max(Hours)
             for DOW in ([1],[2],[3],[4],[5],[6],[7]) ) as pvt
    

    I used the following to set up data to test this with:

    DROP TABLE MyTable
    CREATE TABLE MyTable
     (
        Project    varchar(10)  not null
       ,Category   varchar(10)  not null
       ,Date       datetime     not null
       ,Hours      int          not null
     )
    
    INSERT MyTable
     values 
    ('Proj1', 'test', '8/2/2010',  2 ),
    ('Proj1', 'test', '8/3/2010',  8 ),
    ('Proj1', 'test', '8/4/2010',  4 ),
    ('Proj1', 'test', '8/5/2010',  3 ),
    ('Proj1', 'test', '8/6/2010',  5 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a table set up as follows: |ID|EmployeeID|Date |Category |Hours| |1 |1 |1/1/2010
I need to have MySQL query like this one: UPDATE table_name SET 1 =
If i have a sq-table relation model that looks like this: Project <----> ProjectActivity
I have 2 tables set up like this (irrelevant rows omitted): > product -
I have a table and I would like to be able to set up
I have a set of tables in Oracle and I would like to identify
I have a table set up as follows id origin destination carrier_id so typical
I have a pretty standard table set-up in a current application using the .NET
I have a mysql table field set as time type which stores data in
I have a table that containts a set of columns one of it is

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.