37
Views
5
Comments
Solved
SQL query

Hello there,
I have a complex aggregate for my screen, and I want to replace it with data action and use SQL widget.
I attached details of my aggregate and the structure of my data action/SQL. Could any one help with the SQL widget?

Thank you inadvance for your help.




Screenshot 2025-05-16 083339.png
Screenshot 2025-05-16 083250.png
Screenshot 2025-05-16 083726.png
2016-04-22 00-29-45
Nuno Reis
 
MVP
Solution

Hello.


Here is some general advice on how to proceed:
1. Input Parameters: Identify any filters that your aggregate might be using with external values and create Input Parameters for them in your SQL.


2. Query Construction: All your aggregate joins could be represented as JOINs in SQL, and your aggregate filters can be WHERE statements in SQL.  "With or Without" is "Left Join". "Only With" is "Inner Join".


3. Return Data: The SQL widget returns a List of a certain structure, so make sure to define your structure as output parameter for the widget.

Please, keep in mind, the SQL Widget should only be used when the aggregate cannot solve your use case or if you need to optimize a complex query. OutSystems aggregates abstract away concepts such as denormalization and protect against injection attacks. Hence, ensure the SQL queries are correctly optimized and secure.

2024-04-15 01-01-11
Fatemeh Safinia

Hello Nuno, 

Thanks for sharing your knowledge

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @Fatemeh Safinia ,

if it is because of a lack of SQL knowledge, here's a tip to help you come up with the SQL : execute the aggregate in service studio, and then look at the generated SQL.  This will be with table names and column names instead of entity names and attribute names, but it will help you construct your own SQL.

Dorine

2024-04-15 01-01-11
Fatemeh Safinia

Hello Dorine,

That was a really good one, thanks

2016-04-22 00-29-45
Nuno Reis
 
MVP
Solution

Hello.


Here is some general advice on how to proceed:
1. Input Parameters: Identify any filters that your aggregate might be using with external values and create Input Parameters for them in your SQL.


2. Query Construction: All your aggregate joins could be represented as JOINs in SQL, and your aggregate filters can be WHERE statements in SQL.  "With or Without" is "Left Join". "Only With" is "Inner Join".


3. Return Data: The SQL widget returns a List of a certain structure, so make sure to define your structure as output parameter for the widget.

Please, keep in mind, the SQL Widget should only be used when the aggregate cannot solve your use case or if you need to optimize a complex query. OutSystems aggregates abstract away concepts such as denormalization and protect against injection attacks. Hence, ensure the SQL queries are correctly optimized and secure.

2024-04-15 01-01-11
Fatemeh Safinia

Hello Nuno, 

Thanks for sharing your knowledge

2024-10-12 12-11-20
Kerollos Adel
Champion

hallo @Fatemeh Safinia  ,

I think you need to go through the conversion process step by step:

  1. Retrieve all the necessary tables using INNER JOIN or LEFT JOIN, depending on your business logic.

  2. Define the required input parameters and implement the conditional logic based on your specific requirements.

  3. Don’t forget to include sorting, as it may impact the usability or correctness of the result.

  4. Make sure to apply record limits (e.g., maximum number of records to return) to ensure good performance, especially with large datasets.

  5. Start by creating your DTO (Data Transfer Object) and select only the specific columns you need to return, to match your structure and improve performance

    If possible, share a simple OML file — this will help us better understand your scenario and provide a more accurate and helpful solution.


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