Search code examples
splitsnowflake-cloud-data-platform

Snowflake Split ~ How could I obtain the results formatted to use it in the where clause to filter the results?


SET TestVariable = 'Test1, Test2, Test3, Test4';

SELECT SPLIT($TestVariable,',');

--results

[ "Test1", " Test2", " Test3", " Test4" ]

--desired results

('Test1', 'Test2', 'Test3', 'Test4')


Solution

  • enter image description here

    Snowflake Functions used with hyperlink to documentation:

    • LISTAGG()

    • SPLIT_TO_TABLE()

    • TRIM()

        SELECT 
            '('||LISTAGG(''''||TRIM(value)||'''',',')||')'  VOLIA
        FROM 
            TABLE(SPLIT_TO_TABLE('Test1, Test2, Test3, Test4', ','))