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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:42:47+00:00 2026-06-07T06:42:47+00:00

It was hard to condense in the title what I need… Here it goes.

  • 0

It was hard to condense in the title what I need… Here it goes. This is for SQL Server 2008.

For a reason that is too long to explain here, I need to have a SELECT statements that will display, among other columns, a value of 1 if 4 columns have a value null. Something like this.

SELECT name, lastname, p1, p2, p3, p4, "1 if p1,p2,p3 and p4 are all NULL, 0 otherwise" city, st, zip
FROM mytable

The questions is how to I translate to code this: “1 if p1,p2,p3 and p4 are all NULL, 0 otherwise” ?

I tried

CASE len(p1+p2+p3+p4) WHEN NULL 1 ELSE 0 END

But it didn’t work. even though when I do

SELECT len(p1+p2+p3+p4) FROM mytable

The result iS NULL.

I tried IF ELSE, but it doesn’t seem to be welcome in a SELECT statement.

Ideas?

Thanks.


Thanks guys.
I chose the answer that doesn’t use COALESCE because it’s the one I understood. I tried reading MS’s explanation here: http://msdn.microsoft.com/en-us/library/ms190349.aspx and I still didn’t fully understand, plus the note saying that “At least one of the null values must be a typed NULL” scared me off a bit.
Thanks to all.


  • 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-07T06:42:50+00:00Added an answer on June 7, 2026 at 6:42 am

    try this:

        SELECT name, lastname, 
    CASE WHEN  (p1 is null and p2 is null and p3 is null and p4 is null) then 1 
    else 0 end , city, st, zip
        FROM mytable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hard to think of a title for this one! I have a bean that
i hard that TEXT, NTEXT data can not be manipulated from sql server trigger.
Hard to explain this one, but here it goes: I'm using jQuery to add
Hard to come up with a proper title for this problem. Anyway... I'm currently
Hard to put a descriptive title to this which is easy to understand so
Hard to put in words, so here is an screen of this in action:
Physical Hard Drive is shown uninitialized in windows server 2008 even after reboot and
I have a hard-coded if loops that looks like this: my $tp = 0;
Its hard to explain this so I'll try my best. Is it possible to
Kinda hard to explain, but i'll try. I have a datalist that is populated

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.