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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:50:59+00:00 2026-05-27T07:50:59+00:00

I am using SQL Server 2005 and VS 2008.I am having a query as

  • 0

I am using SQL Server 2005 and VS 2008.I am having a query as shown below

SELECT  Month
    , SUM(Man) AS Man
    , SUM(Sal) AS Sal
    , SUM(Man + Sal) AS Total
FROM    (        
      SELECT  DATENAME(MONTH, DOB) AS Month
              , CASE WHEN TypeOfPost = 'Manager' THEN 1 ELSE 0 END AS Man
              , CASE WHEN TypeOfPost = 'Sales' THEN 1 ELSE 0 END AS Sal
      FROM    tableName
    ) g          
GROUP BY
    Month  

which generates the following output

Output--
-------------------------------------
Month      Man      Sal        Total
--------   -----   ------     ---------
January       1       1          2
June          1      NULL        1
November      1       1          2

But now I want to calculate the total of Total column.So help me out.

Expected Output--
-------------------------------------
Month      Man      Sal        Total
--------   -----   ------     -------
January       1         1         2
June          1        NULL       1
November      1         1         2
-------------------------------------
                      Total       5
-------------------------------------
  • 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-27T07:51:00+00:00Added an answer on May 27, 2026 at 7:51 am

    You could use the WITH ROLLUP option in the GROUP BY – this will give you an extra row that contains the “rolled up” (summed up) values:

    SELECT  Month
        , SUM(Man) AS Man
        , SUM(Sal) AS Sal
        , SUM(Man + Sal) AS Total
    FROM    (        
          SELECT  DATENAME(MONTH, DOB) AS Month
                  , CASE WHEN TypeOfPost = 'Manager' THEN 1 ELSE 0 END AS Man
                  , CASE WHEN TypeOfPost = 'Sales' THEN 1 ELSE 0 END AS Sal
          FROM    tableName
        ) g          
    GROUP BY
        Month WITH ROLLUP
    

    The extra line will contain NULL for the Month column, and should sum up all other columns for you

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

Sidebar

Related Questions

Using SQL Server 2005 and 2008. I've got a potentially very large table (potentially
I'm using SQL Server 2008 Management studio viewing a 2005 server and have just
I am using SQL Server 2008 & 2005 (Express). I'm trying to extract part
I am using .Net 2.0 + SQL Server 2005 Enterprise + VSTS 2008 +
I am using .Net 2.0 + SQL Server 2005 Enterprise + VSTS 2008 +
I am looking to manage a SQL Server 2008 DB using Management Studio 2005.
I´m using SQL Server 2005 and Visual Studio 2008, C#. In the data source
I am developing an Windows pplication(using Visual Studio 2008,Sql server 2005). I have to
I am using SQL Server 2005 Express and Visual Studio 2008. I have a
I'm using sql server 2005/2008 and I have a table that it's PK (rec_index)

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.