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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:21:22+00:00 2026-06-12T22:21:22+00:00

Using SQL Server 2000 I want to get the column name and column count

  • 0

Using SQL Server 2000

I want to get the column name and column count where bit is 0,

table1

columnname status(bit)

apple  0
orange 1
graph 0
pine 1
....

I have more than 50 rows in table1, I want to get the columnname and count where bit is 0

Expected Output

apple  
graph 
...
...

Count - 22 (total column count where bit is 0)

How to make a query for the above condition

Need Query Help

  • 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-12T22:21:23+00:00Added an answer on June 12, 2026 at 10:21 pm

    Solutions

    DECLARE @MyTable TABLE (
        ColumnName VARCHAR(50) NOT NULL,
        Status BIT NOT NULL
    );
    
    INSERT  @MyTable (ColumnName, Status)
    SELECT 'apple', 0
    UNION ALL SELECT 'orange', 1
    UNION ALL SELECT 'graph', 0
    UNION ALL SELECT 'pine', 1;
    
    Print 'Solution 0 ... (no grouping, 2 resultsets)'
    SELECT  t.ColumnName
    FROM    @MyTable t
    WHERE   t.Status=0
    SELECT  @@ROWCOUNT AS cnt
    
    Print 'Solution 1 ... (group by ColumnName, 2 resultsets)'
    SELECT  t.ColumnName
    FROM    @MyTable t
    WHERE   t.Status=0
    ORDER BY t.ColumnName
    COMPUTE COUNT(t.ColumnName)
    
    Print 'Solution 2 ... (1 resultset, 2 columns)'
    SELECT  t.ColumnName, COUNT(*)
    FROM    @MyTable t
    WHERE   t.Status=0
    GROUP BY t.ColumnName WITH ROLLUP
    
    Print 'Solution 3 ... (1 resultset, 1 column, last row contains the cnt value)'
    SELECT  CASE WHEN x.IsGrouping=0 THEN x.ColumnName ELSE CONVERT(VARCHAR(11),x.Cnt) END AS CocoJambo
    FROM (
        SELECT  t.ColumnName, 
                COUNT(*) AS Cnt,
                GROUPING(t.ColumnName) AS IsGrouping
        FROM    @MyTable t
        WHERE   t.Status=0
        GROUP BY t.ColumnName WITH ROLLUP
    ) x
    ORDER BY x.IsGrouping
    

    Output

    Solution 0 ... (no grouping, 2 resultsets)
    ColumnName
    ----------
    apple
    graph
    
    cnt
    ---
    2
    
    Solution 1 ... (group by ColumnName, 2 resultsets)
    ColumnName
    ----------
    apple
    graph
    
    cnt
    ---
    2
    
    Solution 2 ... (1 resultset, 2 columns)
    ColumnName 
    ---------- -
    apple      1
    graph      1
    NULL       2
    
    Solution 3 ... (1 resultset, 1 column, last row contains the cnt value)
    CocoJambo
    ---------
    apple
    graph
    2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2000 I want to get Table2.TimeIn Table2.TimeOut according to Table1.personid and
Using SQL Server 2000 I want to get the max(date) of total for each
work on SQL Server 2000. want to Automated Email Notifications using SQL Server Job
Using SQL Server 2000 table1 id values (datatype is nvarchar) 001 12:10 002 01:25
I'm using pyodbc with SQL Server 2000. I want to be able to insert
Using SQL Server 2000 dtptime - datetimepicker (Format: Custom Format(HH:mm) Query insert into table1
Using SQL Server 2000 I want to reduce the decimal length Query Select 23/12
Now, I am using Ms sql server 2000 and I want to store my
Using SQL Server 2000 Table1 Id date --- ---------- 001 23/01/2012 002 25/01/2012 003
Using SQL Server 2000 and VB6 Table1 ID Date 001 20090801 001 20090802 …

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.