I am trying to find the substring between the first ‘a’ char in email column before ‘@’,
i have written the below sql-query ,
but i think i can do it in better way .
SELECT
email,
CASE
WHEN
LENGTH(SUBSTR(email, 0, POSITION('@' IN email))) - LENGTH(REPLACE(SUBSTR(email, 0, POSITION('@' IN email)),
'a',
'')) > 1
THEN
SUBSTR(email,
POSITION('a' IN email) + 1,
POSITION('a' IN SUBSTR(email,
POSITION('a' IN email) + 1)) - 1)
ELSE ''
END AS deelstring
FROM
persoon
correction for the sql-query
2
Answers
You have to test every step of your query epecially, when you want to extract parts.
As ysth Length only can count ascii charakter, which doesn’t matter when you check for if there are any
a
in the email, but when extracting you need the length for all characters even non ASCII.fiddle
There’re at least two ways to extract a substring:
Piggyback on data prepared by @nbk with the 2nd approach, this may work for you:
Outcome: