Home > Forum > Rules, JS, SQL > SQL COOMMAND and empty answers

SQL COOMMAND and empty answers
0

Hello,
I'm wondering is there a simple way to do this. Sometimes "SQL COMMAND" returns nothing (there are no rows that match the query). How do you test for this?
IF "SQL COMMAND [...]" = EMPTY does not seem to work. Maybe there is a workaround?

In reply to: Christian Amler

I would use Exist query.

If exists (SELECT field1 from table1 where condition) select 1 else select 0

Will return 1 if there is at least one result line for your query, and 0 if it gets no matches.

Thank you Daniel and Christian, I combined your answers and it works :) Did one business rule to detect if the query will return something or not and another rule to return the actual value if the result of the first is 1. Works fine for now :)

MVP
In reply to: Christian Amler

I would use Exist query.

If exists (SELECT field1 from table1 where condition) select 1 else select 0

Will return 1 if there is at least one result line for your query, and 0 if it gets no matches.

Hi Christian,

you are right, in most cases returning a true/false directly would be better. In my case I'm reusing the SQL command (business rule) inside the action. Since I don't want to duplicate the command , I prefer having a single point of failure, I've used this approach.

Best regards,
Daniel

Did you know that with WEBCON you can automate virtually any process? Even baking cookies 🍪
 
Speaking of cookies: we use the ones that are essential for our website to function properly, as well as additional ones that help us customize our content to your preferences. If you don’t mind cookies, click Accept. If you want to learn more, explore settings.
Settings