Injecting multi-select parameters in Custom SQL

There are times you might want to filter a custom SQL table by a parameter selection… and there are times you may want all rows to show if no selections are made.

If you wanted to only show rows where one column’s value is in the parameter selection (and show nothing if no selections are made), the SQL is simple:

SELECT *
FROM table
WHERE name IN {{Name-Parameter}}

If you want to show all rows when no parameter selection has been made, you can use the following:

SELECT *
FROM table
WHERE
CASE WHEN
LEN(ARRAY_TO_STRING(ARRAY_CONSTRUCT{{Name-Parameter}},‘,’) ) = 0
THEN True
ELSE name IN {{Name-Parameter}} END