Skip to content
Advertisement

How to verify if array list is empty in SQL

I have a multilist field returning a list of values.

My query is filtering the list using IN (list), but if the user do not select anything is list, it returns an empty list, or null (I can’t see).

I’m trying to do something like:

    case when @list is null then 1
             when c.SK_dimLocalizacao in (@list) then 1
             else 0
        end = 1

It works when I select none or one value, but if I select more than one it bring me an error.

I already tried to use:

    case when @list = '' then 1
             when c.SK_dimLocalizacao in (@list}) then 1
             else 0
        end = 1

I can’t modify the query in backend because i’m using Pentaho.

Advertisement

Answer

Maybe this? (not sure if I understand the end goal)

IF LEN(ISNULL(@list,'')) <> 0
BEGIN
   --Query for if the list isn't empty or null
END
ELSE
   --Query for if the list is empty or null
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement