I need to display the keyboard players from a list of bands, and I've been able to using the following SQL:
SELECT BAND.NAME AS Band_Name, KBPLAYER.NAME AS Keyboard_Player
FROM BAND
FULL OUTER JOIN (
SELECT M.NAME, MO.BID
FROM MEMBEROF MO, MEMBER M
WHERE MO.INSTRUMENT='keyboards'
AND M.MID=MO.MID
) KBPLAYER
ON BAND.BID=KBPLAYER.BID
ORDER BY BAND.NAME, KBPLAYER.NAME
The above query displays the names of all the band and the keyboard player (if any) in that band, but I also want to display 'No KeyBoard Players' for those bands that don't have a keyboard player. How can I achieve this? Please let me know if you need me to furnish with details of the table structure.
Update: Please note that I'm not able to use any of the SQL3 procedures
(COALESCE, CASE, IF..ELSE
). It needs to conform strictly to SQL3 standard.
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.
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.
In SQL Server, ISNULL() function is used to replace NULL values.
NVL : Converts null value to an actual value. NVL2 : If first expression is not null, return second expression. If first expression is null, return third expression. the first expression can have any data type. COALESCE : Return first not null expression in the expression list.
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
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