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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:22:56+00:00 2026-05-23T11:22:56+00:00

Evidentally, I can’t do this: SELECT SUM( t.MyField IS NULL ) AS totalNulls, SUM(

  • 0

Evidentally, I can’t do this:

SELECT 
  SUM( t.MyField IS NULL ) AS totalNulls, 
  SUM( t.MyField LIKE '[0-9]') AS totalNumbers
FROM MyTable AS t;

I don’t know why these don’t work, since booleans in SQL are just numbers (0 and 1). But the errors I’m getting suggest it is not legal to have ‘is null’ or ‘like’ anywhere in the select clause. Why aren’t they legal there? How do I achieve the intended effect, as suggested by the (pseudo) SQL above?

  • 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-23T11:22:57+00:00Added an answer on May 23, 2026 at 11:22 am

    If your data isn’t indexed on the queried column you should use the CASE-based solution Aaron recommended because the rows will only be queried once.

    select  totalNulls = sum(case when MyField is null then 1 else 0 end),
            totalNumbers = sum(case when MyField like '[0-9]' then 1 else 0 end)
    from    MyTable;
    

    You should know that you only accept e.g. ‘7’ as a number not ’12’ in this case.
    If you want to accept any numbers you’d have to ask

    ... when MyField not like '%[^0-9]%' ...
    

    In this case you could do a charm using isnumeric:

    select  totalNonNumbers = count(*) - sum(isnumeric(MyField)),
            totalNumbers = sum(isnumeric(MyField))
    from    MyTable;
    

    If the column is indexed a variation of Michaels solution could be fastest:

    select  totalNulls = (select count(*) from MyTable where MyField is null),
            totalNumbers = 
              (select count(*) from MyTable where MyField between '0' and '9');
    

    There are so many ways …

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

Sidebar

Related Questions

Can someone help me with this query? SELECT p.OwnerName, SUM(ru.MonthlyRent) AS PotentinalRent, SUM( (SELECT
I'd like to auto-generate an ERD from a SQL Server CE 4.0 database. I
I wrote code like this >>> class a(object): def __init__(self): self.__call__ = lambda x:x
I'd like to love Django, but this business of static and media files in
This was my first go at writing some jQuery code completely from scratch, so
I'd like to do something really simple with boost::python. I can find documentation for
I would like to use a table alias within the projection of another select
I would like to automatically determine all of the properties (including the hidden ones)
Evidently I was really wrong in this thread Should I always use transactions in
Everything in the code below works except for the binding on the ContextMenu. This

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.