◷ Reading Time: 9 minutes
This tutorial shows how to load a filtered data from database and Apply some rules on the data.
- How to connect to a Database
- Filter data on the database side
- Apply some rules on the data
Scenario
We want to apply discount business rules on some data that are in the database.
The idea is
- a flow loads the data from database by passing dateStart and dateEnd to database query
- Then iterates on the loaded data, and sets discount for each individual car based on below business rules
If Year is between 2012 and 2015 then Discount is 10% If Year is between 2015 and 2017 then Discount is 4% If Year is 2017 then Discount is 1% Otherwise no Discount
Main Flow
The idea is
- A flow loads the relevant amount of data from the database by passing dateStart and dateEnd input parameters. So not all the data is loaded.
- Using a Loop to iterate on the loaded data, and sets Discount for each individual car
New Generic Flow
Create a new project and add a Flow as below:

Use Toolbox and Drag and Drop tools from it to the surface of Flow to create the above diagram.

The above Flow below nodes:
- a Generic Flow
- Start
- Database
- Loop
- End
Add Flow Parameters
Add the below parameters to flow
- cars (Out): List of the cars read from the database
- car (Local): Individual car to set the discount
- dateStart (In): Start year to filter data
- dateEnd (In): End year to filter data

Database Access
You need to
- Set connection string
- Add a query to load data
Connection String
Connect string can be static inside the flow model or can be passed on by your application. In this example, we use the static method.


Add Query
In the database’s Properties Window




And you finally have the query ready:


And you finally have the query ready:

Rules
In this example, we use a Decision Table for the above rules. To model the above rules:



And you will have an empty Decision Table as below:

Our Decision Table is going to set a Discount on a Car
- Define and Input Parameter called car for this decision table
- And we will have
- One condition (year ranges)
- One action (discount assignment)
The final DT is like below:

Expressions settings are:
- Condition Year: car.Year
- Action Discount: car.Discount
Finalizing Flow
The last step is to finalize the flow to iterate over the cars and pass them to the Decision Table. Now we are going to link the Loop node to flow parameters:



Do the same for Item Name and select car and you will have the below properties:

Run
In the Flow, press F5 and the Data Deed Provider screen appears. Then use Data Composer and assign dateStart and dateEnd as below:
- dateStart = 2014
- dateEnd = 2017

When the Flow is run, you can use the data viewer to explore your data. Before going to the Decision Table you can view the below values:

And after running the Decision Table containing the running business rules against the loaded data, you see below result:

Setup Your Database
In this example, we use MsSql, Create a new database called Car-Insurance, and use below scripts to set up the table and data:
Sample Project
Use the attachment at the end of the page to download the sample project (Data-and-Rules.zip).