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

  • SEARCH
  • Home
  • 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 985419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:09:39+00:00 2026-05-16T05:09:39+00:00

How do i count null values while making cross tab query? I have a

  • 0

How do i count null values while making cross tab query?

I have a table with three colums [id, name, answer]

i have following records:

ID  NAME   ANS
1   ABC    1
1   ABC    0
1   ABC    NULL
2   XYZ    1
2   XYZ    NULL
2   XYZ    NULL
2   XYZ    1
2   XYZ    0
1   ABC    0

now i would like to get my result:

ID  Name   NULLCOUNT     TRUE COUNT   FALSE COUNT
1   ABC    1             1            2
2   XYZ    2             2            1

I am using following SQL Statement:

select ID, NAME, 
    sum(case ANS when null then 1 else 0 end) as NULLCOUNT,
    sum(case ANS when 1 then 1 else 0 end) as TRUECOUNT,
    sum(case ANS when 0 then 1 else 0 end) as FALSECOUNT
from 
    TBL1
 Group By ID, Name

Getting my result:

ID  Name   NULLCOUNT     TRUE COUNT   FALSE COUNT
1   ABC    0             1            2
2   XYZ    0             2            1

The NULL Count is getting error. Why and how can i solve this?

  • 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-16T05:09:40+00:00Added an answer on May 16, 2026 at 5:09 am

    I believe instead of this:

     sum(case ANS when null then 1 else 0 end) as NULLCOUNT
    

    You should use this:

     sum(case when ANS is null then 1 else 0 end) as NULLCOUNT
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I exclude null values from a count on an array? since count
I'm trying to count the number of records that have a null DateTime value.
Example: select count(*) from my table where column1 is not null and (column1 =
i have this JSON object: {error:null, result:[{id:1234567890, count:1, recipients: [u3848, u8958, u7477474 ], dateCreated:2012-06-13T09:13:45.989Z
I have a temp table that needs the values of a Stored procedure. So
Consider I have three columns of values as follows, Col-A Col-B Values 1 2
I have this joining table: CREATE TABLE [TagMap]( [intItemId] [bigint] NOT NULL, [intTagId] [bigint]
Is there a fast way to count the amount of successive null bytes starting
void SaveFiles(out XElement Attachments) { Attachments = null; if (Uploader1.UploadedFiles.Count() > 0) { Attachments
The following code is throwing the error this.element is null. However, the wid_cont 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.