简体   繁体   中英

How to add a select all option in a sql databricks parameter? Or if the parameter value is null make it select all?

So I want to create a select all button in a parameter. The actual parameter has around 200 options because of the size of the database. However, if I want a general summary where you can see all the options i would have to select one by one and that is not efficient. Any ideas?

Select
*
from Table
where store in ({{store}}) or ({{store}}) is null

I tried this but it didn´t let me use the parameter as null. Also it is important to mention that the parameter uses values from another query where the distinct names of the stores are listed.

IN clause can't be used with WHERE . You should use = , > , or < .

SELECT * FROM <Table_name> WHERE store > <value> OR store IS NULL; .

Refer WHERE clause for more details.

You could add '--- All Stores ---' to your list. Here is the query I would use to populate the drop down.

SELECT
    store as store_name
FROM
    (
    Select Distinct
      store
    From 
      Table

    UNION ALL

    SELECT
      '--- All Stores ---' AS store
    )
ORDER BY
  store_name 

    

Next the query that uses the drop down

Select
  *
FROM 
  Table
WHERE 
  (store in ({{store_name}}) or '{{store_name}}' LIKE '--- All Stores ---')

Now if you select '--- All Stores ---' you should get all of the stores :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM