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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:17:23+00:00 2026-05-18T02:17:23+00:00

I am working on a appliaction in which I have a following schema Tasks

  • 0

I am working on a appliaction in which I have a following schema

Tasks Master

Task_ID
Task_Name

Task_Details

Task_ID
Task_Date
Task_Count (can be any number like 2 or 3 or 4 or 40)

the Input Form is like that which the staff will fill at the end of the day.

Date | Task Name | Task_Count

24/01/2010 | How many cheque books issued today | 12
24/01/2010 | How many ATM Issued today | 7

Now I want a matrix report showing all tasks suppose 28 tasks in vertical row and on given month it should show all the dates of the particular month horizontal direction like from 1 to 31 days or 30 or 28 as per month days with the task_count using PIVOT in query. i am failed to produce the result as i dont know to make it work. please help.

thanks

  • 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-18T02:17:24+00:00Added an answer on May 18, 2026 at 2:17 am

    You’ll need to use a dynamic query since the columns returned by the pivot changes each month.

    With some time this could probably be made more elegant, but here’s the basic idea:

    declare @StartOfMonth datetime = '11/1/2010';
    declare @counter datetime = @StartOfMonth;
    declare @sql varchar(MAX) = '';
    declare @columnnames varchar(MAX);
    declare @columnfilter varchar(MAX);
    declare @fieldname varchar(12);
    
    --First, create a string of dynamic columns, one for each day of the month.
    WHILE (MONTH(@counter) = MONTH(@StartOfMonth))
    BEGIN
    
        SET @fieldname = '[' + CONVERT(varchar(10), @counter, 101) + ']';
    
        --Wrap the columns in ISNULL(@,0) to avoid having null values for days without tasks.
        SET @columnnames = ISNULL(@columnnames + ',', '') + 'ISNULL(' + @fieldname + ',0) AS ' + @fieldname;
    
        --Also create a dynamic list of the Task_Date values to include in the pivot.
        SET @columnfilter = ISNULL(@columnfilter + ',', '') + @fieldname;
    
    
        SET @counter = DATEADD(DAY,1,@counter);
    END
    
    --Put it all together into a pivot query.
    set @sql = 'SELECT Task_Name, ' + @columnnames + ' FROM (';
    set @sql = @sql + 'SELECT M.Task_Name, D.Task_Date, D.Task_Count '
    set @sql = @sql + 'FROM Task_Detail D JOIN Task_Master M ON D.Task_ID = M.Task_ID) as SourceTable ';
    set @sql = @sql + 'PIVOT (SUM(Task_Count) FOR Task_Date IN (' + @columnfilter + ')) AS PivotTable';
    
    exec (@sql)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Web Application in asp.net 2.0. which is working fine on
hi am working with NSArrays using foundation tool and i have wrote the following
I am working on application which can deal with multiple database servers like "MySQL"
I have some code which is working in iphone and i want to make
I have an application architecture which has following layers (or c# projects). web front
I am working on an application which draws a simple dot grid. I would
I'm currently working on desktop application which calls third party API. After authorizing against
I'm working profesionally on a php web application which contains contacts, among other data.
I'm working on a .Net application which uses Asp.net 3.5 and Lucene.Net I am
I am working on a WPF application which has a treeview that represents an

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.