Reputation: 179
I have some text elements in the column that have a character "|" and the rest right after it I need to get rid of:
campaign
abc
fdg|3234
dfr|4567
I want it to look like:
campaign
abc
fdg
dfr
I tried:
select replace (data_2_crm.campaign, '_|_', '' ) from data_2_crm
select trim (trailing '.*|' from campaign) from data_2_crm
select trim (trailing '%|' from campaign) from data_2_crm
It didn't work. Please help!
Upvotes: 0
Views: 3006
Reputation: 520918
Use a regex replacement on the pattern \|.*$
:
SELECT
campaign,
REGEXP_REPLACE(campaign, '\|.*$', '') AS new_campaign
FROM data_2_crm;
Upvotes: 1
Reputation: 1269503
Use split_part()
:
select t.*, split_part(campaign, '|', 1)
from data_2_crm;
Upvotes: 1