Is there a way to insert a zero instead of NULL while performing LEFT OUTER JOIN on two tables?
Suppose I have a query like this:
SELECT * FROM
(SELECT uID from Class) T1
LEFT OUTER JOIN
(SELECT pID from University) T2
ON T1.uID = T2.pID
CASE WHEN T1.uID IS NULL
THEN 0
ELSE T1.uID
END AS uID`
Correct me if I'm wrong
UPDATE [table] SET [column]=0 WHERE [column] IS NULL; 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.
ISNULL() function, CASE statement, COALESCE() function can be used to replace null values in a SQL Server table. To replace null with specified replacement value, we can use any of the following: ISNULL() function.
The SQL LEFT JOIN returns all rows from the left table, even if there are no matches in the right table. This means that if the ON clause matches 0 (zero) records in the right table; the join will still return a row in the result, but with NULL in each column from the right table.
A left outer join displays the null value in the first table. The results make it difficult to distinguish a null in the data from a null that represents a failure to join. When null values are present in data being joined, it is usually preferable to omit them from the results by using a regular join.
use ISNULL(field, 0)
this will insert zero if the field is NULL
CASE WHEN a.fieldname IS NULL
THEN 0
ELSE a.fieldname
END AS fieldname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With