Reputation: 43
My table in snowflake has a column with string values. The string has comma and slash. I need to list only the values before first comma or slash. I used snowflake SPLIT function, with that i could only get rid of either of one (comma or slash but not both) character.
Input values:
Compact SUV/Crossover
Luxury Subcompact SUV/Crossover
Subcompact Car,Sports Car
Luxury Car,Luxury Sports Car
Compact Car,Hybrid/Alternative Energy Car
Entrylevel Luxury Car
Midsize Car
Desired output :
Compact SUV
Luxury Subcompact SUV
Subcompact Car
Luxury Car
Compact Car
Entry level Luxury Car
Midsize Car
Upvotes: 1
Views: 2227
Reputation: 59175
A simple regex should help:
select regexp_substr(s, '^[^,/]*')
from (
select 'Compact Car,Hybrid/Alternative Energy Car' s
)
Upvotes: 2