PROPER: from Tableau to SQL

Capitalizes the first character of each word. Below, 8 sample rows go through the calculation and through the SQL, and both return the same numbers.

Calculated field

PROPER([label])

Sample data

labelquantityamountflag
cedar cedar 6512.8True
ORCHID-west66-7.6False
maple-east670null
willow north6825.3True
birch-birch694.9False
pine/south70-1.2null
ash719True
nullnullnullnull

The same calculation as SQL

SELECT array_to_string(list_transform(regexp_extract_all(lower(label),'[a-z0-9]+|[^a-z0-9]+'), x -> upper(left(x,1)) || substr(x,2)), '') AS result FROM input

Runs the example above.

Result

result
Cedar Cedar
Orchid-West
Maple-East
Willow North
Birch-Birch
Pine/South
Ash
null

Same rows from the calculation and from the SQL in DuckDB.

Where a naive translation goes wrong

  • Snowflake INITCAP and BigQuery INITCAP use their own word-delimiter profiles; review delimiters.

    Naive SQL

    SELECT upper(label) AS result FROM input
    result
    CEDAR CEDAR
    ORCHID-WEST
    MAPLE-EAST
    WILLOW NORTH
    BIRCH-BIRCH
    PINE/SOUTH
    ASH
    null

    Matches the calculation

    SELECT array_to_string(list_transform(regexp_extract_all(lower(label),'[a-z0-9]+|[^a-z0-9]+'), x -> upper(left(x,1)) || substr(x,2)), '') AS result FROM input
    result
    Cedar Cedar
    Orchid-West
    Maple-East
    Willow North
    Birch-Birch
    Pine/South
    Ash
    null

Signature

PROPER(string)