I have a table in which values inserted from another SQL in all columns. Table structure like as
CREATE TABLE temp_t
(
catalog_item_code VARCHAR(1000),
line_trans_type VARCHAR(1000),
ref_trans_no VARCHAR(1000)
)
And values like as
INSERT INTO temp_t
VALUES (' DR-1002-0001, DR-1010-0001, DR-20180926-05, RO-M-2059, HU-3154-2040, JRCEKB-SS-1550-0001',' SALES, SALES, RETURN, RETURN, SALES, SPO',' 201681, 201681, 201666, 201660, 201681, 201648')
Currently when we run SELECT for above table, we get output like:
I want to make a well formed string(line_trans_type +' - '+ref_trans_no +char(9)+ catalog_item_code) with each of the comma separated value from every column(if contain values) like
SALES - 201681 DR-1002-0001
SALES - 201681 DR-1010-0001
RETURN - 201666 DR-20180926-05
RETURN - 201660 RO-M-2059
SALES - 201681 HU-3154-2040
SPO - 201648 JRCEKB-SS-1550-0001
I tried with the following query but it always repeats all catalog_item_code with every row.
SELECT
REPLACE(line_trans_type , ',', '-' +
REPLACE(ref_trans_no, ',', char(9) + REPLACE(catalog_item_code, ',', char(13))))
FROM
temp_t
Thanks in advance.

STRING_AGG.