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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:28:36+00:00 2026-05-23T17:28:36+00:00

This query returns one row with columns Ready, Processing, Complete, Failed and Error with

  • 0

This query returns one row with columns Ready, Processing, Complete, Failed and Error with totals for each. Is there a way to rewrite this query so that columns that have a total of zero are not returned?

I’m using this to populate the mschart control and I don’t wan’t labels on the chart if there are 0 instances of that category.

SELECT        
              SUM(CASE WHEN Status = 'R' THEN 1 ELSE 0 END) AS Ready,
              SUM(CASE WHEN Status = 'P' THEN 1 ELSE 0 END) AS Processing, 
              SUM(CASE WHEN Status = 'C' THEN 1 ELSE 0 END) AS Complete,
              SUM(CASE WHEN Status = 'F' THEN 1 ELSE 0 END) AS Failed,
              SUM(CASE WHEN Status = 'E' THEN 1 ELSE 0 END) AS Error
FROM  MailDefinition 
  • 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-23T17:28:38+00:00Added an answer on May 23, 2026 at 5:28 pm

    What I would do is take what you have, throw it into an unpivot, then remove all of the 0 records.

    select
        Type, 
        Sum
    from
    (
        SELECT                       
            SUM(CASE WHEN Status = 'R' THEN 1 ELSE 0 END) AS Ready,               
            SUM(CASE WHEN Status = 'P' THEN 1 ELSE 0 END) AS Processing,                
            SUM(CASE WHEN Status = 'C' THEN 1 ELSE 0 END) AS Complete,               
            SUM(CASE WHEN Status = 'F' THEN 1 ELSE 0 END) AS Failed,               
            SUM(CASE WHEN Status = 'E' THEN 1 ELSE 0 END) AS Error 
    FROM  MailDefinition 
    ) a
    unpivot
    (
         Sum for Type in ([Ready],[Processing],[Complete],[Failed],[Error])
    ) u
    where Sum>0
    

    That does, of course, entail changing your chart some.

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

Sidebar

Related Questions

this query will just one row as a result myDataContext db = new myDataContext();
Can anyone explain why this query returns an empty result. SELECT * FROM (`bookmarks`)
I have a LINQ query that returns some object like this... var query =
I'd like to make an (MS)SQL query that returns something like this: Col1 Col2
This query is related to this one I asked yesterday. I have a radio
This is basically an extension of Update multiple rows with one query? . I
I know there are similar questions to this one, but I haven't found any
I have a SQL query that returns two columns - Title and Count. When
I need to build a MySQL query that returns only the common columns for
Is there a valid way in SQL Server 2005 to read a row of

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.