Rahul Patidar
Rahul Patidar

Reputation: 209

DB2 query is not giving any data after adding blank column in select statement

I am trying to select data from db2 in '|' seprated format i have 20 column in my table out of 20 in 19 column i have data for these 19 column when i am selecting data i am getting data but in last column(column no 20 i dant have any data its blank) when i am adding this 20th column in my scripts i am not getting any data also its taking lot of time and not showing any data I'm using below query.

    select
    col1 ||'|'
    ||col2 ||'|'
    ||col3 ||'|' 
    ||col4 ||'|' 
    || col5 ||'|'
    ||col6||'|' 
    ||col7 ||'|'
    ||col8 ||'|' 
    || col9||'|'
    ||col10 ||'|'
    || col11||'|' 
    ||col12 ||'|'
    || coll3||'|'
    ||col14 ||'|'
    || col15||'|' 
    ||col16 ||'|'
    ||col17 ||'|'
    ||col18 ||'|' 
    ||col19||'|'
    ||col20 from tablename;
    

can someone please guide me what's wrong here why i am not getting data if am adding this blank column.even when i am dong simple select col20 from tablename then also its taking lot of time,query is getting stuck and not giving any data.

Upvotes: 0

Views: 63

Answers (1)

mao
mao

Reputation: 12267

If you concat with NULL the result is NULL.

If the columnName (e.g. col20) can contain NULL you can use COALESCE(columnName,'-') ,which will put a hyphen to indicate null.

Choose any character or string you prefer if you prefer a different character, or just use at least one space.

Upvotes: 1

Related Questions