138
Views
12
Comments
Solved
how to find if the input for SQL is IS NULL
Question
Application Type
Reactive

Hi,

I wrote a custom SQL to make use of IN operator, however I need to use the IN operator if the input parameter is not null, if it's null I've to pull the entire data set, I did something like 

WHERE @param IS NULL or @param = '' or {entity}.id IN(@param), but it's throwing an error.


Thanks,

Sai

2019-01-07 16-04-16
Siya
 
MVP
Solution

The condition WHERE @param IS NULL OR @param = '' OR {entity}.id IN(@param) becomes WHERE IS NULL OR = '' OR {entity}.id IN() when @param is empty. This is syntactically incorrect, leading to the error.  Hence it is better to conditionally execute the SQL query only if your list is not empty.

2020-05-07 18-53-00
Rui Barradas
 
MVP

Hello Jeevan,

Hope you're doing well.

What exactly is the error that you're getting?

2019-01-07 16-04-16
Siya
 
MVP
Solution

The condition WHERE @param IS NULL OR @param = '' OR {entity}.id IN(@param) becomes WHERE IS NULL OR = '' OR {entity}.id IN() when @param is empty. This is syntactically incorrect, leading to the error.  Hence it is better to conditionally execute the SQL query only if your list is not empty.

2024-05-22 06-12-56
Vignesh Prakash

Hi @Jeevan Sai Sabbavarapu

Can you please share the sample OML or screenshot of the error message that you are encountering. 

Thanks,
VP.

2024-05-14 06-49-08
Karnika-EONE

Hi @Jeevan Sai Sabbavarapu 

Use this query:

SELECT *

FROM {entity}

WHERE CASE

    WHEN @param IS NULL THEN TRUE//it return all records.

    ELSE @param IN ({entity}.id)

END;

Hope it helps,Thanks.

Thanks

Karnika


2021-06-26 17-42-52
Jeevan Sai Sabbavarapu

No, it'll not work as explained by @Siya as it's Expand inline property parameter itself convert into empty.

2023-12-11 06-54-51
Deepali Nayak

Hi Jeevan,
Hope you are doing well.
Can you please share data type of @Param also screenshot of error you are facing.

2023-12-14 09-56-57
Yogesh Javir

Hello @Jeevan Sai Sabbavarapu
try below

where case when @param is null then true else  {entity}.id IN(@param) 
but before using input parameter in query, you need to mark it as expand inline to yes.

2025-11-25 13-20-12
Tamirys Silva Barina

Hi @Jeevan Sai Sabbavarapu 

You can add another parameter (of type boolean) to your query, and write the following condition. This way, the query will return all users if @UserId is null, otherwise, it will filter the users based on the provided @UserId list.

In the Sql properties you must pass:

Note: The inline parameter must be sanitized before being passed to the SQL. You can use the BuildSafeText action which will return a safe in clause string. 

Regards,

Tami


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Jeevan,

Input parameters can never by NULL unless they are Identifiers. In your case, for "IN (@param)" to work, @param needs to be an Expand Inline parameter, which means it's the literal text pasted into your query. Which means that when it is empty, you'll get a syntax error in your SQL, as your "IN (@param)" evaluates to "IN ()", which is illegal. Therefore you'll need to ensure that @param at least contains a value, that won't match. So for an integer/identifier list, it's probably "0", and for a text identifier list or text list, its "''" (two single quotes). In that case, you can then do something like:

WHERE @param = '' OR {Entity}.[TextAttribute] IN (@param)

or

WHERE @param = 0 OR {Entity}.[Id] IN (@param)


2021-06-26 17-42-52
Jeevan Sai Sabbavarapu

@Kilian Hekhuis  Interesting, I'll give a try and let you know.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
2023-12-14 09-56-57
Yogesh Javir

Guys,

If my answer is not working as expected, then suggest your idea by replying to my comment but don't do thumbs down.

@Jeevan Sai Sabbavarapu 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.