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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:09:45+00:00 2026-06-17T09:09:45+00:00

I need to write a statement to display every column in a table, the

  • 0

I need to write a statement to display every column in a table, the count and percentage of records with that column populated, and the distinct count of values.

For example if I had a table Address containing:

Addr1 | AddrText  | PostalCode
11111 | demo ave  | 91210
22222 | demo2 ave | null
33333 | null      | null

It should display something like:

columns    | Count | Percentage
Addr1      | 3     | 100
AddrText   | 2     | 66.6
PostalCode | 1     | 33.3

Or have the columns remain the same and put only the data as rows, but I figured the above may be easier.

ps: Sorry if I couldn’t get the formatting right but I hope you get the idea.

  • 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-17T09:09:46+00:00Added an answer on June 17, 2026 at 9:09 am

    You can unpivot the columns using UNION ALL and then apply an aggregate function to get the count and percentage:

    select col,
      count(case when col is not null and value is not null then 1 end) CntCol,
      (count(case when col is not null and value is not null 
             then 1 end) / count(col))*100.0 Percentage
    from
    (
      select 'Addr1' col, Addr1 value
      from yourtable
      union all 
      select 'AddrText' col, AddrText value
      from yourtable
      union all 
      select 'PostalCode' col, PostalCode value
      from yourtable
    ) src
    group by col
    

    See SQL Fiddle with Demo

    The result is:

    |        COL | CNTCOL | PERCENTAGE |
    ------------------------------------
    |      Addr1 |      3 |        100 |
    |   AddrText |      2 |   66.66667 |
    | PostalCode |      1 |   33.33333 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write SQL statement that will return an html table and specify
I need to write a case statement that will return 1 of 3 if
I need to write a function that can take an if statement at runtime
I need to make a query to ContactsContract.Data table and values in CONTACT_ID column
I need to write a conditional statement that would check if L tab is
I need to write an insert statement into a table the columns looks like
I need write an update statement that used multiple tables to determine which rows
I need to write the following SQL statement in LINQ lambdas : SELECT *
I need to write a C++ code coverage program that takes in another C++
I need to write a program that prints 0.(03) for input 1 and 33.

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.