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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:51:23+00:00 2026-06-03T20:51:23+00:00

I need to fill a bar chart with data. I have everything in place.

  • 0

I need to fill a bar chart with data. I have everything in place. I have the sql query used to gather the data.

What I am looking for is the best way to provide data for the current month and the last 11 months (12 months total).

This code will give me the information for the current month up until today. How can I modify this so it will also give me the information for the previous 11 months?

Would this modification be made to the query or would we loop over the query 12 times?

protected void FillChart ()
{
    DateTime now = DateTime.Now;
    DateTime startDate = now.AddDays( 1 - now.Day );
    DateTime endDate = now;
    string query;

    query = "SELECT SUM(case when r.Type in ('Programming-Billable', 'Consulting-Billable') then r.Minutes_Spent";
    query += " end) AS 'Custom Programming and Consulting',";
    query += " SUM(case when r.Type in ('Data Maintenance', 'Tech Support-Billable', 'Training') then r.Minutes_Spent";
    query += " end) AS 'Tech. Support / Data Maint. / Training'";
    query += " FROM TK_Project p ";
    query += " INNER JOIN TK_Task t";
    query += " ON p.Project_ID = t.Project_ID ";
    query += " JOIN TK_Time_Record r";
    query += " ON t.ID = r.Task_ID";
    query += " WHERE p.Company = " + Session[ "Distid" ];
    query += " AND p.Name ='Technical Support' ";
    query += " AND r.Work_Date BETWEEN  '" + startDate + "'  AND  '" + endDate + "' ";
    query += " AND r.Type NOT LIKE '%non%'";


    DataTable data = GeneralFunctions.GetData( query );
}

The query currently returns the following results:

Custom Programming and Consulting   Tech. Support / Data Maint. / Training
           90                                           105

EDITED:

SELECT SUM(case when r.Type in ('Programming-Billable', 'Consulting-Billable') then r.Minutes_Spent
           end) AS 'Custom Programming and Consulting',
       SUM(case when r.Type in ('Data Maintenance', 'Tech Support-Billable', 'Training') then r.Minutes_Spent
           end) AS 'Tech. Support / Data Maint. / Training'
FROM TK_Project p 
INNER JOIN TK_Task t
     ON p.Project_ID = t.Project_ID 
JOIN TK_Time_Record r
     ON t.ID = r.Task_ID
WHERE p.Company = 162 AND p.Name ='Technical Support' 
AND r.Work_Date BETWEEN  '04/01/2001'  AND  '04/30/2012' 
AND r.Type NOT LIKE '%non%'
  • 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-06-03T20:51:24+00:00Added an answer on June 3, 2026 at 8:51 pm

    You only need to change start and end date:

    DateTime startDate = now.AddYears( -1 );
    DateTime endDate = now;
    

    By the way, it would probably better to use parameters for both datetimes. So you should pass them to the GetData method and create SqlParameters from it.

    Edit: If you want to have the sum for each month, you need to group by month.

    GROUP BY DATEADD(month, DATEDIFF(month, 0, Work_Date),0)
    

    You can omit the enddate if you want to get all records until now anyway:

    SELECT SUM(case when r.Type in ('Programming-Billable', 'Consulting-Billable') then r.Minutes_Spent
               end) AS 'Custom Programming and Consulting'
         , SUM(case when r.Type in ('Data Maintenance', 'Tech Support-Billable', 'Training') then r.Minutes_Spent
               end) AS 'Tech. Support / Data Maint. / Training'
         , DATEADD(month, DATEDIFF(month, 0, Work_Date),0) AS Month
    FROM TK_Project p 
    INNER JOIN TK_Task t
         ON p.Project_ID = t.Project_ID 
    JOIN TK_Time_Record r
         ON t.ID = r.Task_ID
    WHERE p.Company = 162 AND p.Name ='Technical Support' 
    AND r.Work_Date BETWEEN  @startDate  AND  GetDate()
    AND r.Type NOT LIKE '%non%'
    GROUP BY DATEADD(month, DATEDIFF(month, 0, Work_Date),0)
    Order By Month
    

    Note that i’ve added the @startDate as parameter.

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

Sidebar

Related Questions

I need to build a custom designed bar chart that displays some simple data.
Nightly, I need to fill a SQL Server 2005 table from an ODBC source
I need to backup the original data from a table so I can fill
I have two fields that need to multiply each other and fill a third
I need to fill the progress bar according to the current value of a
i need help regarding the save menu item i have in my menu bar.
I have an absolute positioned div that I need to get to to fill
I need to fill a multidimensional array and here is my code I have
I have a form and I need to fill in the options of a
Looking for some examples of iText 5 and ColdFusion 7. I need to fill

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.