SQL Replace NULL Values with Own text SQL Replace NULL Values with Own text sql sql

SQL Replace NULL Values with Own text


Use the coalesce function. This function returns the first of it's arguments that are not null. Eg:

COALESCE(KBPLAYER.NAME,'No KeyBoard Players') AS Keyboard_Player


I've decided to do it differently since I wasn't going anywhere with the above SQL. I'll appreciate if anyone has suggestions to make for the above SQL with the set constraints.

SELECT   band.name AS Band_Name, 'NULL' AS Keyboard_PlayerFROM   memberofINNER JOIN  memberON   memberof.mid = member.mid FULL JOIN   bandON   memberof.bid = band.bid AND   instrument = 'keyboards'WHERE    member.name IS NULL UNIONSELECT   band.name AS Band_Name, member.name AS Keyboard_PlayerFROM   memberofINNER JOIN  memberON   memberof.mid = member.mid FULL JOIN   bandON   memberof.bid = band.bid WHERE  instrument = 'keyboards'


As per your comment to replace empty string to some text, the simple solution is to use case statement like below.

SELECT BAND.NAME AS Band_Name, CASE WHEN KBPLAYER.NAME = '' THEN 'No Player' ELSE KBPLAYER.NAME END AS Keyboard_PlayerFROM BANDFULL OUTER JOIN (    SELECT M.NAME, MO.BID    FROM MEMBEROF MO, MEMBER M    WHERE MO.INSTRUMENT='keyboards'    AND M.MID=MO.MID    ) KBPLAYERON BAND.BID=KBPLAYER.BIDORDER BY BAND.NAME, KBPLAYER.NAME