Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace null string with null value

I have a table that has a string value of 'null' that I wish to replace with an actual NULL value.

However if I try to do the following in my select

Select Replace(Mark,'null',NULL) from tblname

It replaces all rows and not just the rows with the string. If I change it to

Select Replace(Mark,'null',0) from tblname

It does what I would expect and only change the ones with string 'null'

like image 597
BlueBird Avatar asked Jun 15 '16 18:06

BlueBird


People also ask

How do I replace a NULL in a string?

You can use String's replace() method to replace null with empty String in java. str = str. replace(null,""); As String is immutable in java, you need to assign the result either to new String or same String.

How do you replace a NULL value in a string in SQL?

Null Values can be replaced in SQL by using UPDATE, SET, and WHERE to search a column in a table for nulls and replace them. In the example above it replaces them with 0.

How do you change NULL to value?

We can replace NULL values with a specific value using the SQL Server ISNULL Function. The syntax for the SQL ISNULL function is as follow. The SQL Server ISNULL function returns the replacement value if the first parameter expression evaluates to NULL.

How do you replace a NULL with string in tableau?

The steps are simple: Change the data type of the Date to a String (right-click on the field in the list of dimensions and Change Data Type) Right-click on the dimension again (once it's a string) and select Aliases. Set the Alias value for Null to be a space if you want it blank (or a “-“/dash/hyphen/minus/etc)


1 Answers

You can use NULLIF:

SELECT NULLIF(Mark,'null') 
FROM tblname;
like image 181
Lamak Avatar answered Sep 22 '22 09:09

Lamak