Select more than one column as null

0

I have the following query in SQL SERVER:

Select Column1, Column2, Column3 
FROM DBO.DATA

as a result the following:

COLUMN1  COLUMN2    COLUMN3
A          Q          P
B          NULL       O
NULL       R          L
C          T          G

I want to obtain all the records that in some of their columns have null and in another query I want to obtain the records that in none of the columns have null

    
asked by DEVJ 22.05.2017 в 19:39
source

2 answers

0

If what you want is a kind of "indicator" of nulls, the answer would be something like this:

Indicate which ones are null in any of its columns

select (case when column1 is null 
             then 'column1 is null'
             else (case when column2 is null 
                       then 'column2 is null'
                       else 'column3 is null'
                  end) 
       end ) cual_es_nula  
  from dbo.data 
where column1 is null or column2 is null or column3 is null; 

I think the other case can be drawn from this easily.

    
answered by 23.05.2017 / 09:22
source
0

Those that are not null in any column:

 SELECT Column1, Column2, Column3
 FROM DBO.DATA
 WHERE Column1 IS NOT NULL AND Column2 IS NOT NULL AND Column3 IS NOT NULL

To get the ones with a NULL value, you only have to use the IS NULL operator

 SELECT Column1, Column2, Column3
 FROM DBO.DATA
 WHERE Column1 IS NULL OR Column2 IS NULL OR Column3 IS NULL
    
answered by 22.05.2017 в 19:42