I am using the below query to produce a pipe delimited file but I also want pipe delimited column name. Can you please help me with that.
select cast (sample_dt||'|'||trim(trailing '.' from trim(leading ' ' from acct_id))||'|'||name1||'|'||ent_sub_lob||'|'||app_dt||'|'||home_phn_num||'|'||city_1_name||'|'||geo_st_cd||'|'||surveyid||'|'||study_type||'|'||ent_lob||'|'||channel||'|'||market_C||'|'||merchant_id as char(300))
from ud.testing;
If i understand you correctly, you either need a table column name or your current derived column ie cast (sample_dt||'|'||trim(trailing '.' from.....
name as |
separated. In both cases, you just need double quotes ""
around column name as below.
In Create Table:
create TABLE t1(
"x1 | y1" char(300)
);
You can check created table definition with show
command.
show TABLE t1;
CREATE SET TABLE t1 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
"x1 | y1" CHAR(300) CHARACTER SET LATIN NOT CASESPECIFIC)
PRIMARY INDEX ( "x1 | y1" );
In derived column:
SELECT 'abc'||' | '|| 'zyc' as "Test | ABC";
Test | ABC
----------
abc | zyc
You current query will become.
SELECT CAST (sample_dt||'|'||trim(TRAILING '.'
FROM trim(LEADING ' '
FROM acct_id))||'|'||name1||'|'||ent_sub_lob||'|'||app_dt||'|'||home_phn_num||'|'||city_1_name||'|'||geo_st_cd||'|'||surveyid||'|'||study_type||'|'||ent_lob||'|'||channel||'|'||market_C||'|'||merchant_id AS char(300)) AS "Pipe | Seperated"
FROM ud.testing;
Hope it will help :-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.