How to replace comma in the beginning and end of the result while using LISTAGG? I tried LTRIM but not getting the correct result.
SELECT s_id
,REGEXP_REPLACE(rewrd_card_nbr, '\null|id not found|no value|no-value|blank|null|''|', '')
AS RESULT
,MIN(TRY_TO_NUMBER(other.item_pg_nbr)) AS item_pg_nbr
FROM table_1 S
JOIN table_2 P
ON P.click_stream_integration_id = S.click_stream_integration_id
WHERE s_id IN ('1217423213611638899263'
,'2988822682711638898987'
,'8131301001481638906163'
,'8030711031105116372833'
,'7806180295006814765443'
,'6215684539960126690425'
,'6502689315628777977858'
,'6959274311947723444672'
,'1235659053876083630210'
,'5958673331149776209626'
,'1587460374618074937485'
)
GROUP BY s_id,rewrd_card_nbr
ORDER BY TRY_TO_NUMBER(item_pg_nbr);
After adding LISTAGG in the Outer Query, I'm getting the result -
- only comma for few rows
- comma at the beginning and end
- Blank value
- ,,
I want the commas to be removed and the blank value to be replaced as 'NO VALUE'
Something is missing in my code. Please share your thoughts. Thanks!

