Sql query that does not return null values ​​as a result

I am really new to sqlserver.

I request some data from the database, and also returns null values ​​with the result.

My request:

select amount, distributorid from paymants

Some distributors have null valuesat amount column.

Please, help!

thanks

+4
source share
6 answers

You must use is null(or is not null) to filter null values.

select amount, distributorid 
from paymants
where amount is not null

If you need all records with a zero sum with a different value (for example, -1), you can use isnullor coalesce, as shown below.

select coalesce(amount,-1) amount, distributorid 
from paymants

Or, if you only need the number of null entries, you could do:

select amount, distributorid 
from paymants
where amount is null 
+6
source

,

SELECT amount, distributorid FROM paymants WHERE amount IS NOT NULL  

, , , .

, , , NOT NULL

CREATE TABLE example ( someColumn INT NOT NULL )
+1

, NULL, 0, :

SELECT ISNULL(amount,0), distributorid FROM paymants

ISNULL → http://technet.microsoft.com/en-us/library/ms184325.aspx

, , , , :

select amount, distributorid 
from paymants
where amount is not null
+1

( WHERE), .

SELECT amount, distributorid 
FROM paymants
WHERE amount IS NOT NULL
0

SELECT amount, distributorid FROM paymants WHERE amount NOT NULL

0

SOLUTION-1:

If you just need to return non-zero values, try the following:

select amount, distributorid 
from paymants
where amount is not null

SOLUTION-2:

If you need to not only return values ​​that are not null, but also need to change the null values ​​to blank lines or any other default value, try the following:

First, change all null values ​​to blank lines or the default value, say 0:

update paymants
set amount = ''
or amount = 0
where amount is null

Then select the entries:

select amount, distributorid
from paymants

Hope these solutions will clear your confusion.

0
source

All Articles