I would like to concat multiple columns into a single column. When a value is Null I wish not to show it but I do want to show the values that exist. I couldn't find an example stackoverflow, below is a table of result set I'm trying to get, however, in this case because the "email" is null the entire result set is null not sure why this is occurring. I apologize in advance for my table if it doesn't display properly I've been using senseful github to create my table(s) but when I copy and paste here it displays weird.
SELECT
Id,
'study_id:' || study_id ||' , ' || 'email:' || email ||' , ' || 'phone:' || phone AS "Longvalue",
FROM
mv_itest mi
| id | Longvalue |
|---|---|
| 123 | study_id:123 , phone:123-123-1234 |
This is the result set if I use concat, however, I do not wish to display the alias for phone if the value is null
+-----+-----------------------+--+ | id | longvalue | | +-----+-----------------------+--+ | 987 | study_id:456 , phone: | | +-----+-----------------------+--+
||operator immediately returnsNULLif any of the operandsIS NULL(yes, I think this painful-by-default design is another demonstration of the ISO SQL commitee's latent sadism) - the solution is to useCONCAT()instead, which behaves like you want.