Questions tagged [nullif]

NULLIF is an ISO/ANSI SQL standard function that takes two arguments. If the two arguments are equal, then the NULL value is returned. Otherwise, the first argument is returned.

The NULLIF function takes two arguments. If the two arguments are equal it returns NULL. Otherwise, the first argument is returned.

Syntax:

NULLIF ( <expression 1>, <expressions 2> )

It is the same as the following CASE expression:

CASE WHEN <expression 1> = <expression 2> THEN NULL
     ELSE <expression 1>
END
FROM <table>;

In action:

SELECT NULLIF(100, 100); -- the same values, NULL 
Result: NULL              

SELECT NULLIF(101, 100); -- different values, returns the first.
Result: 101                   

It is available in MS SQL Server, SQL, Oracle, Teradata, etc.

61 questions
0
votes
3 answers

Nullif - using in Coldfusion

Looking for a little help with this code. Without posting the entire file which is way to big I just need a little help with using Nullif in Coldfusion. I could I guess use it in my SQL statment, but for the sake of learning I am wondering if it…
CarolaV
  • 41
  • 3
0
votes
1 answer

Oracle SQLLDR - Load Record with Invalid Date, Replace Invalid Date with Null

There are records in my source text file with invalid date values. The invalid date values are inconsistent in format due to manual entry. I still want to load all of these records, but I want to replace the invalid date value with a null. Please…
Beemer12
  • 1
  • 2
0
votes
1 answer

Wrapping ISNULL around NULLIF

Suppose that I have: case when @ID ='2386002' then ISNULL(nullif(i.call,''),i.standingOrderNumber) when nullif(rtrim(i.call),'') is null then nullif(rtrim(i.standingOrderNumber), '') else case when…
Temp034
  • 141
  • 11
0
votes
2 answers

SQL Change Null date or 1-1-1900 00:00:00 to Current Date

I googled a couple of hours so far, and tried many different things, but somehow what works with others doesn't seem to work on my dataset. *EDIT: DBMS: SQL Server. + Code below Let's say this is the…
titatovenaar
  • 309
  • 4
  • 12
0
votes
1 answer

multiple coalesce and ifnull strings with carriage returns in sql (db2)

I am trying to combine multiple data points into one cell using coalesce and ifnull with carriage returns between the combined data points. If I remove the second coalesce statement it works, but so far no luck combining more than two sets of data.…
Andrea
  • 23
  • 4
0
votes
1 answer

How to handle NULLIF and ISNULL of SQL statements in C# ASP.net?

I have some SQL statements (written by someone else) which I am trying to understand. In this SQL, it calculates 'Weight' as shown below. ISNULL(NULLIF(CASE WHEN ISNULL(m.Override,0) = 1 THEN m.OverWeight ELSE…
toofaced
  • 141
  • 4
  • 18
0
votes
1 answer

Using NULLIF with Psycopg2 type error

I'm trying to use the NULLIF function to filter out some empty entries in an INSERT INTO command via psycopg2. The problem is it won't work if the column expects a numeric, as the NULLIF function seems to be interpreted as text. My table contains 5…
sc28
  • 1,163
  • 4
  • 26
  • 48
0
votes
2 answers

Division gives values 0

In order to avoid division by 0 I am using CAST AS FLOAT and NULLIF. But for some reason it gives me values as 0. All I am doing is dividing Declined on Submissions What am I doing wrong? SELECT [Status Reason], b.MonthNum, …
Serdia
  • 4,242
  • 22
  • 86
  • 159
0
votes
1 answer

NULLIF produces incorrect output in Amazon Redshift?

This following code should produce the same values for columns lag and lag2: CREATE TABLE bug1 ( id INT, value INT ); INSERT INTO bug1 VALUES (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3); SELECT id, value, (LAG(value) OVER…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
0
votes
1 answer

Sql loader NULLIF with TERMINATED BY '\t'

i am trying to load my data in my table. My data is terminated by '\t' and when I try: OPTIONS (SKIP=0) load data infile 'C:\*' APPEND into table Table1 FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS ( FNAME …
user3602755
  • 27
  • 1
  • 6
0
votes
2 answers

NULLIF in SQL Loader to compare a string value

I have a file with simple rows that I want to upload into a table using sql loader. However, there is a column that contain values that I want to exclude: e.r. 123;Código Postal *;HH;456 523;Código Postal *;HI;459 723;Código Postal *;HM;450 The…
Khristian Liahut
  • 195
  • 1
  • 6
  • 24
0
votes
1 answer

How to Use Round And nullif together?

I have a column that calculates Unit Weight (g) by doing the following calculations SELECT ROUND (Weight,0) / nullif ([Units per Carton],0) * 454 AS [Unit Weight (g)] FROM [Item Master] I used the nullif to eliminate the divide by zero. but i also…
HackGod555
  • 134
  • 12
-1
votes
2 answers

SELECT a decimal if NULL show N/A else show USD Amount

I have a field called Amount type of Decimal(12,2). Amount, can accept NULL and decimal value example 100.00. SELECT NULLIF(Amount, 'N/A') AS Amount FROM PRODUCTS; This cause: Error converting data type varchar to numeric. I want to SELECT a…
henryloke
  • 67
  • 5
-1
votes
1 answer

Need to get null back rather than divide by zero

I had to change my old query to a new query to get the correct results. My old query used to return a null in the denominator, so I didn't have to worry about divide by zero, the new query returns divide my zero for 'M' (R_NTWK_CHNNL), but for 'S'…
Frederica
  • 35
  • 5
-1
votes
1 answer

How to run NULLIF() efficiently to only start from last empty value in mysql?

timestamp column_a column_b 2020 4 alpha 2019 5 '' 2018 '' beta 2017 8 -1 2016 -1 theta I'm trying to replace values using NULLIF() in frequently updating mysql database. In order to…
Scapedee
  • 47
  • 7