MST QNB
MST QNB

Reputation: 293

How to exclude rows with null values in all columns?

I writing a view query requiring a very long SQL script with a lot of joining. There are some values lead to null values in all columns coming from one of the tables.

Basically, my question is there any way to exclude results that end up all null?

might system object help in this case?

Upvotes: 1

Views: 5043

Answers (2)

John Cappelletti
John Cappelletti

Reputation: 82010

Bit of a hack, but you can use concat() in the final WHERE

Example

Declare @YourTable table (ID int,colx varchar(50) ,coly varchar(50), colz int)
Insert Into @YourTable values
(1,'aa','bb',25),
(2,'aa',null,50),
(3,null,null,null)

Select *
 From  @YourTable 
 Where concat(colx,coly,colz)>''

**Returns **

ID  colx    coly    colz
1   aa      bb      25
2   aa      NULL    50

Upvotes: 2

Bibin Mathew
Bibin Mathew

Reputation: 465

IS NOT can filter NULL values in the columns

refer https://learn.microsoft.com/en-us/sql/t-sql/queries/is-null-transact-sql

Upvotes: 0

Related Questions