Extracting Last Name and First Name (Space-Delimited)
Target data
imazaj#XSMALL@SQLDB.PUBLIC>select name from CUSTOMERS limit 5;
+-------------+
| NAME |
|-------------|
| η³ε‘ ζ |
| ι·ε θ³’δ» |
| ιδΈ θ£δΉ |
| ι«ζΎ ιΎ |
| ε°ε ζ
ε€ͺι |
+-------------+
Use the POSITION function. Equivalent to STRPOS in PostgreSQL, INSTR in Oracle.
POSITION β Snowflake Documentation
POSITION( <expr1>, <expr2> [ , <start_pos> ] ) POSITION( <expr1> IN <expr2> ) Arguments Required: expr1 A string or binary expression representing the value to search for. expr2 A string or binary expression representing the value to search. Optional: start_pos A number indicating the position to start the search (1 represents the start of expr2). Default: 1
select
name,
SUBSTR(name, 1, POSITION(' ', name) -1) as lastname,
SUBSTR(name, POSITION(' ', name)) as firstname
from
customers
limit 5;
imazaj#XSMALL@SQLDB.PUBLIC>select
name,
SUBSTR(name, 1, POSITION(' ', name) -1) as lastname,
SUBSTR(name, POSITION(' ', name)) as firstname
from
customers
limit 5;
+-------------+----------+-----------+
| NAME | LASTNAME | FIRSTNAME |
|-------------+----------+-----------|
| η³ε‘ ζ | η³ε‘ | ζ |
| ι·ε θ³’δ» | ι·ε | θ³’δ» |
| ιδΈ θ£δΉ | ιδΈ | θ£δΉ |
| ι«ζΎ ιΎ | ι«ζΎ | ιΎ |
| ε°ε ζ
ε€ͺι | ε°ε | ζ
ε€ͺι |
+-------------+----------+-----------+
5 Row(s) produced. Time Elapsed: 0.974s