0

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!

1

2 Answers 2

1

Use a regex replacement on the pattern \|.*$:

SELECT
    campaign,
    REGEXP_REPLACE(campaign, '\|.*$', '') AS new_campaign
FROM data_2_crm;

screen capture from demo link below

Demo

Sign up to request clarification or add additional context in comments.

Comments

1

Use split_part():

select t.*, split_part(campaign, '|', 1)
from data_2_crm;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.