This SSRS SQL is used to pull allergies from an oracle database. It works great except that the allergies display like this: Aspirin, Pencillin, Tetracycline,,,,,,,, We want to keep the commas between the allergies but need to remove the trailing commas so that it displays like this: Aspirin, Penicillin, Tetracycline Can you help us with this please?
SELECT
RES2.PSEQ,
TRIM(MAX(RES2.D1) || ' ' || MAX(RES2.D2) || ' ' || MAX(RES2.D3) || ' '
|| MAX(RES2.D4) || ' ' || MAX(RES2.D5) ||' '|| MAX(RES2.D6) || ' '
|| MAX(RES2.D7) || ' ' || MAX(RES2.D8)||' '|| MAX(RES2.D9) || ' '
|| MAX(RES2.D10) || ' ' || MAX(RES2.D11)||' || MAX(RES2.D12) || ' '
|| MAX(RES2.D13) || ' ' || MAX(RES2.D14)||' '|| MAX(RES2.D15) || ' '
|| MAX(RES2.D16) || ' ' || MAX(RES2.D17)||' '|| MAX(RES2.D18) || ' '
|| MAX(RES2.D19) || ' ' || MAX(RES2.D20)||' '|| MAX(RES2.D21) || ' '
|| MAX(RES2.D22) || ' ' || MAX(RES2.D23)||' '|| MAX(RES2.D24) || ' ' || MAX(RES2.D25)) ALGS
FROM
(SELECT
RES1.PSEQ,
DECODE(RES1.ALN,1,RES1.ALGS) D1,
DECODE(RES1.ALN,2,RES1.ALGS) D2,
DECODE(RES1.ALN,3,RES1.ALGS) D3,
DECODE(RES1.ALN,4,RES1.ALGS) D4,
DECODE(RES1.ALN,5,RES1.ALGS) D5,
DECODE(RES1.ALN,6,RES1.ALGS) D6,
DECODE(RES1.ALN,7,RES1.ALGS) D7,
DECODE(RES1.ALN,8,RES1.ALGS) D8,
DECODE(RES1.ALN,9,RES1.ALGS) D9,
DECODE(RES1.ALN,10,RES1.ALGS) D10,
DECODE(RES1.ALN,11,RES1.ALGS) D11,
DECODE(RES1.ALN,12,RES1.ALGS) D12,
DECODE(RES1.ALN,13,RES1.ALGS) D13,
DECODE(RES1.ALN,14,RES1.ALGS) D14,
DECODE(RES1.ALN,15,RES1.ALGS) D15,
DECODE(RES1.ALN,16,RES1.ALGS) D16,
DECODE(RES1.ALN,17,RES1.ALGS) D17,
DECODE(RES1.ALN,18,RES1.ALGS) D18,
DECODE(RES1.ALN,19,RES1.ALGS) D19,
DECODE(RES1.ALN,20,RES1.ALGS) D20,
DECODE(RES1.ALN,21,RES1.ALGS) D21,
DECODE(RES1.ALN,22,RES1.ALGS) D22,
DECODE(RES1.ALN,23,RES1.ALGS) D23,
DECODE(RES1.ALN,24,RES1.ALGS) D24,
DECODE(RES1.ALN,25,RES1.ALGS) D25
FROM
(SELECT
A.PAT_SEQ PSEQ,
D.ALLERGEN_DESCRIPTION ALGS,
ROW_NUMBER() OVER (PARTITION BY A.PAT_SEQ ORDER BY
D.ALLERGEN_DESCRIPTION) ALN
FROM
ENT.PATIENT A,
ENT.CPI_ALLERGY D
WHERE
D.CPI_SEQ=A.CPI_SEQ AND
A.FACILITY_ID=(@VARIABLE('facility')) AND
A.DEPT_ID=(@VARIABLE('dept')) AND
D.INACTIVE_DT IS NULL) RES1) RES2
GROUP BY RES2.PSEQ
SELECT
RES2.PSEQ,
TRIM(MAX(RES2.D1) || ' ' || MAX(RES2.D2) || ' ' || MAX(RES2.D3) || ' '
|| MAX(RES2.D4) || ' ' || MAX(RES2.D5) ||' '|| MAX(RES2.D6) || ' '
|| MAX(RES2.D7) || ' ' || MAX(RES2.D8)||' '|| MAX(RES2.D9) || ' '
|| MAX(RES2.D10) || ' ' || MAX(RES2.D11)||' || MAX(RES2.D12) || ' '
|| MAX(RES2.D13) || ' ' || MAX(RES2.D14)||' '|| MAX(RES2.D15) || ' '
|| MAX(RES2.D16) || ' ' || MAX(RES2.D17)||' '|| MAX(RES2.D18) || ' '
|| MAX(RES2.D19) || ' ' || MAX(RES2.D20)||' '|| MAX(RES2.D21) || ' '
|| MAX(RES2.D22) || ' ' || MAX(RES2.D23)||' '|| MAX(RES2.D24) || ' ' || MAX(RES2.D25)) ALGS
FROM
(SELECT
RES1.PSEQ,
DECODE(RES1.ALN,1,RES1.ALGS) D1,
DECODE(RES1.ALN,2,RES1.ALGS) D2,
DECODE(RES1.ALN,3,RES1.ALGS) D3,
DECODE(RES1.ALN,4,RES1.ALGS) D4,
DECODE(RES1.ALN,5,RES1.ALGS) D5,
DECODE(RES1.ALN,6,RES1.ALGS) D6,
DECODE(RES1.ALN,7,RES1.ALGS) D7,
DECODE(RES1.ALN,8,RES1.ALGS) D8,
DECODE(RES1.ALN,9,RES1.ALGS) D9,
DECODE(RES1.ALN,10,RES1.ALGS) D10,
DECODE(RES1.ALN,11,RES1.ALGS) D11,
DECODE(RES1.ALN,12,RES1.ALGS) D12,
DECODE(RES1.ALN,13,RES1.ALGS) D13,
DECODE(RES1.ALN,14,RES1.ALGS) D14,
DECODE(RES1.ALN,15,RES1.ALGS) D15,
DECODE(RES1.ALN,16,RES1.ALGS) D16,
DECODE(RES1.ALN,17,RES1.ALGS) D17,
DECODE(RES1.ALN,18,RES1.ALGS) D18,
DECODE(RES1.ALN,19,RES1.ALGS) D19,
DECODE(RES1.ALN,20,RES1.ALGS) D20,
DECODE(RES1.ALN,21,RES1.ALGS) D21,
DECODE(RES1.ALN,22,RES1.ALGS) D22,
DECODE(RES1.ALN,23,RES1.ALGS) D23,
DECODE(RES1.ALN,24,RES1.ALGS) D24,
DECODE(RES1.ALN,25,RES1.ALGS) D25
FROM
(SELECT
A.PAT_SEQ PSEQ,
D.ALLERGEN_DESCRIPTION ALGS,
ROW_NUMBER() OVER (PARTITION BY A.PAT_SEQ ORDER BY
D.ALLERGEN_DESCRIPTION) ALN
FROM
ENT.PATIENT A,
ENT.CPI_ALLERGY D
WHERE
D.CPI_SEQ=A.CPI_SEQ AND
A.FACILITY_ID=(@VARIABLE('facility')) AND
A.DEPT_ID=(@VARIABLE('dept')) AND
D.INACTIVE_DT IS NULL) RES1) RES2
GROUP BY RES2.PSEQ