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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:36:06+00:00 2026-05-27T16:36:06+00:00

How can I do with SQL Server to get a single row where the

  • 0

How can I do with SQL Server to get a single row where the only non-null values are the ones that are consistent and non-null through all the selected rows.

 A    B     C     D
10   NULL  text  NULL
4    abc   text  NULL
4    def   text  NULL

Should give the following row:

 A    B     C     D
NULL NULL  text  NULL
  • 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-27T16:36:06+00:00Added an answer on May 27, 2026 at 4:36 pm
    declare @t table(A int, b varchar(10), c varchar(max), d int)
    
    insert @t values(10, null, 'text', null)
    insert @t values(4, 'abc', 'text', null)
    insert @t values(10, 'def', 'text', null)
    
    
    select case when max(rna) > 1 then null else min(a) end, 
    case when max(rnb) > 1 then null else min(b) end, 
    case when max(rnc) > 1 then null else min(c) end, 
    case when max(rnd) > 1 then null else min(d) end 
     from 
    (
    select rna = rank() over(order by a),
    rnb = rank() over(order by b),
    rnc = rank() over(order by c),
    rnd = rank() over(order by d),
    a, b,c,d
     from @t
     ) e
    

    If you have text columns replace the column type with varchar(max). Text columns are outdated.

    Using count(distinct col1) was by first thought, but it doesn’t count null values.

    select count(distinct a) from (select cast(null as int) a) b 
    

    returns 0 rows

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

Sidebar

Related Questions

How can I get a SQL dump of a SQL Server 2008 database? That
Question: I can get the SQL Server database language by querying: SELECT @@language And
In SQL server you can use the DATENAME function to get the day of
Where can I get the 64 bit bootstrapper for SQL Server Express 2005 64
How can I get the list of available databases on a SQL Server instance?
I'm using SQL Server 2005 and would like to know how I can get
I have a few SQL Server tables with a datetime field that really only
Can SQL Server 2000 be used as the database for LINQ to SQL? Does
I can see SQL Server Compact Destination under Data Flow Destinations, but I am
Using SQL Server 2008. I have a table variable with a single column and

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.