Replace null values in cell - openrefine

I am unable to replace null values in cells. I have created a facet to only display cells that have null values. I then went to edit cells > Transform function and tried to use the replace function but it does not seem to be working.
Different things I have tried:
replace(value, null, 'other_text')
replace(value, 'null', 'other_text')
I expected the null values to be replaced with 'other text'
Screenshot:

You are not replacing the value null, but the string 'null'. The correct syntax for replacing is value.replace('old','new') or replace(value,'old','new'). But replacing doesn't work on null. You should either create a facet for null-values (your current screenshot shows some non-null-values) and fill the expression field with 'new' or you could do something like if(value==null,'new',value).

Related

How do I build a SQL insert query that allows me to insert a blank into a numeric field?

I have some values from an Excel workbook that I'm adding into an array. Eventually, I loop through the array and build a sql insert query (using Excel VBA) with the values stored into the array.
I debugged the sql query string I built and it appears as this:
INSERT INTO RAPTOR_BG.Project_Attributes (
P-Key,
Contract_Currency,
FX_Rate,
Rate_Discount,
Study_Award,
BLD,
Submitted_Date
)
VALUES (
'1111111|7-22-2020',
'USD',
'0.91',
'',
'5-29-2019',
'',
'7-22-2020'
);
Both Rate_Discount and BLD are numeric and won't accept ' '. Is there a way to get sql to accept this blank as a null? I did some research and I saw that some people have had success using a case statement, but all of the examples I've seen use variables or something like this (#SomeName) found in the answer here.
I've tried adapting my code to fit the examples I've seen by doing the below, but it kicked an error stating that at least one of the result expressions in a CASE specification must be an expression other than the NULL constant.
*insert statement from before*
VALUES (
'1111111|7-22-2020',
'USD',
'0.91',
CASE WHEN '' is null then null end,
'5-29-2019',
'',
'7-22-2020'
);
I'm going to be running my code on several hundred workbooks and some of these values will be blank and others won't be so I can't necessarily hardcode a null instead of the ' '. Is there a way to work around getting the numeric fields to accept a blank as null?
Ok, I figured this one out. Please find the answer below.
INSERT INTO RAPTOR_BG.Project_Attributes (
P-Key,
Contract_Currency,
FX_Rate,
Rate_Discount,
Study_Award,
BLD,
Submitted_Date
)
VALUES (
'1111111|7-22-2020',
'USD',
'0.91',
CASE WHEN '' is null then 0 end,
'5-29-2019',
CASE WHEN '' is null then 0 end,
'7-22-2020'
);

Empty string vs NULL

I've a table where some rows have some blank cells. I tried to select such rows using IS NULL function. But the query select 0 rows.
select * from zzz_fkp_registration_female where fname is null;
(0 row(s) affected)
Now I changed my query to:
select * from zzz_fkp_registration_female where fname is null or fname ='';
I got the desired result.
Why is IS NULL not giving the result? What is the difference between IS NULL and '' since the cells are empty. Please explain.
Some differences between them:
NULL can be assigned to any type, as opposed to empty string which won't be compatible with date/numerical fields.
NULL is an UNKNOWN value, it doesn't have a value as opposed to an empty string, which is a value, but empty one.
As far as I'm aware of, NULL shouldn't capture memory as opposed to an empty string which does.
null = null will result in null as opposed to ''='' which will result in TRUE.
You can have your query modified as below:
select * from zzz_fkp_registration_female where isnull(fname,'') = '';
This query will result all the blanks cells as well as cell with null values.
Note:
NULL values represent missing unknown data.
Blank data is actual data entered as blank during input.
Null is an absence of a value. An empty string is a value, but is just empty.
Null is special to a database.
Null has no bounds, it can be used for string, integer, date, etc. fields in a database.
NULL isn't allocated any memory, the string with NUll value is just a pointer which is pointing to nowhere in memory. however, Empty IS allocated to a memory location, although the value stored in the memory is "".
By using NULL you can distinguish between "put no data" and "put empty data".
Some more differences:
A LENGTH of NULL is NULL, a LENGTH of an empty string is 0.
NULLs are sorted before the empty strings.
COUNT(message) will count empty strings but not NULLs
You can search for an empty string using a bound variable but not for a NULL. This query:
SELECT *
FROM mytable
WHERE mytext = ?
will never match a NULL in mytext, whatever value you pass from the client. To match NULLs, you'll have to use other query
SELECT *
FROM mytable
WHERE mytext IS NULL
He can't find NULL because it doesn't have a value
An empty string is a value, but its empty.
Only if its a value it can compare with another value
It is because a cell containing NULL and an empty cell are 2 different things.
i.e. -> NULL is not as same as '' or "".

Replacing multiple null value columns with blank in tableau

I have data source which consist of 16 columns. Many of these columns consist of null values. I have to replace null value columns with blank (all columns at a time).
When I surfed on internet I got one solution as create calculated field to replace null values using IFNULL() function. If I'll use this solution then I've to create 16 calculated fields for every single column.
Is there any solution so that I can replace all null columns with blank simultaneously? Is there any GLOBAL setting which will help me to achieve this?
Thank you.
BLANK is the default replacement for NULL in Tableau.
You can set how Tableau treats NULLs by measure:
Right-Click the measure and select 'Format':
On the left, you will see "Special Values" section:
Set the test to whatever you want.
Use LOOKUP() function, for the columns where values are present, it shows the value else blank or '-'.
For e.g LOOKUP(SUM(Sales) , 0)
for null

to store values with % into column of datatype decimal(28,9)

I use the following code to substring values from text file and store in a table:
CASE
WHEN ISNUMERIC(SUBSTRING(Record,82,11))=1
THEN (LTRIM(RTRIM(CAST(REPLACE(SUBSTRING (Record,82,11),',','')AS DECIMAL(28,14)))))
ELSE NULL
END
the problem I'm facing is that when the substring contains value like '0.098467%', null values are updated in the table. Could someone please help me resolve this.

In SMSS what's the difference between NULL and nothing, in a query result?

I know this maybe a newbie question, but i'm wondering why I sometimes get NULL in a result, and sometimes it's just totally blank - shouldn't they all be null?
As you can see, the Remarks column has no background color of yellow which indicates that it is not NULL. (NULL values has.)
It contains an empty string '' (or maybe spaces) which is different from NULL because empty string is set as empty while NULL is not set (nothing).
In Oracle, the empty string is treated as NULL. SQL Server treats it as a string value.
The main difference is that in SQL Server you can return results from something like
select * from mytable where myfield = ''