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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:34:42+00:00 2026-05-20T13:34:42+00:00

What is the most concise way to return CHAR(1) indicator Y/N if one of

  • 0

What is the most concise way to return CHAR(1) indicator Y/N if one of n columns in a row contain a non-null value?

Performance is important, but not the primary consideration, in this case.

The straightforward way seems to be:

SELECT      CASE WHEN (C.TerminatedDate IS NULL
                       AND C.SelfClosedDate IS NULL
                       AND ...)
                 THEN 'Y'
                 ELSE 'N' END AS 'OpenInd'

  FROM      Customers C

Curious if there is a better way; aware of COALESCE():

SELECT      CASE WHEN COALESCE (C.TerminatedDate, C.SelfClosedDate, ...) IS NULL
                 THEN 'Y'
                 ELSE 'N' END AS 'OpenInd'

  FROM      Customers C

Is there a better way?

Database server is SQL Server 2008.

  • 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-20T13:34:43+00:00Added an answer on May 20, 2026 at 1:34 pm

    Since no one is suggesting it, and the question asks for concise..

    For the same data types, a straight COALESCE is best

    coalesce(a,b,c,d) is not null
    

    If you will be dealing with different data types, try a modified COALESCE

    coalesce(LEFT(a,1),LEFT(b,1),LEFT(c,1)) is not null
    

    Sample:

    create table abc (a int, b datetime, c varchar(max), d image)
    insert into abc select 1, GETDATE(), '', null
    insert into abc select 1, null, '', null
    insert into abc select 1, null, '', 0x123123
    insert into abc select null, null, '', 0x123123
    insert into abc select null, GETDATE(), '', 0x123123
    insert into abc select null, null, null, null
    insert into abc select 88, GETDATE()+3, null, null
    insert into abc select 88, GETDATE()+3, 'gdasdf', null
    insert into abc select null, null, '222', 0x123123
    insert into abc select null, null, 'abcdef', 0x123123
    
    select *, case when coalesce(LEFT(a,1),LEFT(b,1),LEFT(c,1)) is not null then 'N' else 'Y' end
    from abc
    

    If you are not using exotic types like VARCHAR(MAX) or IMAGE, then you can use SQL_VARIANT with COALESCE

    create table abc (a int, b datetime, c varchar(10), d image)
    insert into abc select 1, GETDATE(), '', null
    insert into abc select 1, null, '', null
    insert into abc select 1, null, '', 0x123123
    insert into abc select null, null, '', 0x123123
    insert into abc select null, GETDATE(), '', 0x123123
    insert into abc select null, null, null, null
    insert into abc select 88, GETDATE()+3, null, null
    insert into abc select 88, GETDATE()+3, 'gdasdf', null
    insert into abc select null, null, '222', 0x123123
    insert into abc select null, null, 'abcdef', 0x123123
    
    select *, case when coalesce(convert(sql_variant,a),b,c) is not null then 'N' else 'Y' end
    from abc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the most concise way of converting a java.util.List into a normal JavaFX
I want to specifically invoke the base class method; what's the most concise way
What's the most concise way to determine if @hash[:key1][:key2] is defined, that does not
What is the most concise way of making sure that a Spring bean has
I have a URL in a string. What is the most concise way to
What it is the most brief and concise way of adding event handlers to
What might be the most concise way in bash to convert a number into
What is the most concise and efficient way to find out if a JavaScript
Most concise way to check whether a list is empty or contains only None?
What ist most concise way to read the contents of a file or input

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.