Varun Pathak
Varun Pathak

Reputation: 13

I want to concatenate these case statements

I'm getting multiple results from these statements and want to concatenate these. Please help with syntax and structure

 (SELECT NVL (
              CASE WHEN (csi.hello = DT.S)
                     THEN 'Task IS ALREADY DONE'   
                     WHEN VV.Mo LIKE NULL
                     THEN  'The model is not available'  
                     WHEN (B.tsk = '7')
                     THEN 'The task status has been Cancelled' 
                     WHEN (B.tski = '14')
                     THEN  'The task has been Assigned'  
                     WHEN (B.tsko = '11001')
                     THEN 'The task has been Return Part STATUS'    
                     END, '')RMA_CRITERIA,

Upvotes: 0

Views: 61

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269693

Use string concatenation:

 SELECT (CASE WHEN csi.hello = DT.S THEN 'Task IS ALREADY DONE;' ELSE '' END ||  
         CASE WHEN VV.Mo IS NULL THEN 'The model is not available;' ELSE '' END ||  
         CASE WHEN B.tsk = '7' THEN 'The task status has been Cancelled;' ELSE '' END || 
         CASE WHEN B.tski = '14' THEN  'The task has been Assigned;' ELSE '' END ||  
         CASE WHEN B.tsko = '11001' THEN 'The task has been Return Part STATUS;' ELSE '' END
        ) as RMA_CRITERIA,

Note that this adds a separator (;), although you do not specify one. Also LIKE NULL always returns the equivalent of false; I assume you intend IS NULL. And the ELSE '' is redundant in Oracle, but it makes the intention clear.

Upvotes: 1

Related Questions