
SELECT first_name, last_name, ISNULL(first_name, '') + ISNULL(last_name, '') In order to avoid that and to replace the NULL with empty String, let's use ISNULL() method in our SQL query: You can see that full_name is NULL for the second and third record because for them either first_name or last_name is NULL. SELECT first_name, last_name, first_name + last_name AS full_name FROM #People
#Postgresql replace null with 0 left join full
Now let's display the first name, last name and full name from #People table, where the full name is nothing but a concatenation of first and last name. IF OBJECT_ID( 'tempdb.#People' ) IS NOT NULL DROP TABLE #People ĬREATE TABLE #People (first_name varchar(30), last_name varchar(30)) INSERT INTO #People VALUES ('Joe','Root') INSERT INTO #People VALUES ('Mary', NULL) INSERT INTO #People VALUES (NULL, 'Broad') - cleanup - DROP TABLE #People

In order to understand the problem and solution better, let's create a sample database with some values.
#Postgresql replace null with 0 left join how to
Let's first see, how to use ISNULL() to replace NULL String to empty String in SQL SERVER.

Replacing NULL with blank in SQL SERVER - ISNULL() Example It''s a great course to learn T-SQL concepts, functional, and SQL Server basics. COALESCE(column, column2, ''), so if the column is null then it will use column2 and if that is also null then it will use empty String.įor SQL Server and T-SQL beginners, I also recommend Microsoft SQL for Beginners online course by Brewster Knowlton on Udemy. The only difference between them is that ISNULL() is Microsoft SQL Server-specific but COALESCE() is the standard way and supported by all major databases like MySQL, Oracle, and PostgreSQL.Īnother difference between them is that you can provide multiple optional values to COALESCE() e.g. Similarly, COALESCE(column, '') will also return blank if the column is NULL.

Both functions replace the value you provide when the argument is NULL like ISNULL(column, '') will return empty String if the column value is NULL. There are two ways to replace NULL with blank values in SQL Server, function ISNULL(), and COALESCE(). To prevent this, you can replace NULL with empty String while concatenating. In SQL Server, when you concatenate a NULL String with another non-null String the result is NULL, which means you lose the information you already have. We often need to replace NULL values with empty String or blank in SQL e.g.
