¿Cómo puedo reemplazar la columna ldtext vacía de la tabla de descripción larga en maximo usando sql?

Symptom,Cause,Resolution are not filled up, so it empty, I want to replace the fetched ldtext columns from long description table with some text. I want show null columns with some text in a report.

Gracias

To replace null values in column use COALESCE() function . For DB2 specific solution use IFNULL() función.

SELECT COALESCE(columnName,'Some Text')

OR

SELECT IFNULL(columnName,'Some Text'

SELECT b.ticketid,(SELECT COALESCE(CAST(SYMPTOM.LDTEXT AS VARCHAR(1000),'text') 
                   FROM MAXIMO.LONGDESCRIPTION SYMPTOM  
                   WHERE SYMPTOM.LDOWNERCOL = 'PROBLEMCODE' 
                         AND SYMPTOM.LDOWNERTABLE = 'TICKET' 
                         AND SYMPTOM.LDKEY = B.TICKETUID) AS "symptom" 
FROM incident b

from the above query it doesn't work

SELECT b.ticketid, COALESCE(SELECT CAST(SYMPTOM.LDTEXT AS VARCHAR(1000)) 
                            FROM MAXIMO.LONGDESCRIPTION SYMPTOM  
                            WHERE SYMPTOM.LDOWNERCOL = 'PROBLEMCODE' 
                                  AND SYMPTOM.LDOWNERTABLE = 'TICKET' 
                                  AND SYMPTOM.LDKEY = B.TICKETUID), 'some text') AS "symptom"
FROM incident b

It work as above

preguntado el 12 de febrero de 14 a las 08:02

"Didn't work" isn't a valid complaint; be specific, qué didn't work. What were you expecting. In the case of the first query, you're still anticipating rows in MAXIMO.LONGDESCRIPTION, just not necessarily values in column LDTEXT. In the second, the query works in the absence of rows. It looks like you want a LEFT JOIN, which will probably perform better. Oh, avoid quotations on column names (and other identifiers) - it makes them behave strangely. -

Thanks Muse for your comments, -

1 Respuestas

To replace null values in column use COALESCE() function . For DB2 specific solution use IFNULL() función.

SELECT COALESCE(columnName,'Some Text')

OR

SELECT IFNULL(columnName,'Some Text')

Respondido 12 Feb 14, 08:02

IFNULL only works on db2 for z/OS. Does not work on LUW - AngocA

COALESE(..) is the SQL Standard function anyways, can you give a reason why you're advocating a non-standard function? - Musa Mecánica

Thanks Muse for your comments, I need to clear confusion here, need to show the symptom,cause and resolution in the report from incident management, where ever these are null columns or without data i need to place some text the above three columns replacing blank. - Roshan Jameer

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.