Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
463 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Creating your first flows in Power Automate Desktop Part three of a three-part series of blogs |
---|
Creating your first flows in Power Automate Desktop
|
This blog will show you how to use Power Automate Desktop to connect to a SQL database, execute a SQL statement to retrieve data then test that data using an IF action. Here's what I want my flow to do:
My plan for the various actions needed to complete the flow.
First create a new flow and give it a suitable name.
You can use up to 256 characters for a flow name.
My first action will be to create a connection to the SQL database using a connection string.
Despite PAD not having many actions for SQL, this is all you will need.
Add the Open SQL connection actions to your flow.
You can enter a connection string manually or build a connection string by clicking the icon highlighted above.
I'll choose to build a connection string to illustrate the steps involved.
Step 1 is to choose the type of connection to use. The default type is highlighted and is correct in this case.
With the connection type chosen I can click the Next >> button.
I need to enter the specific details for the SQL connection.
Enter the name or instance of SQL server.
Enter how you will log on to this server.
Select the database to connect to.
The correct details for my connection have been entered. Clicking the Test Connection button will show if the connection works.
At this point I could click OK and continue but for completeness I'll look at the 2 remaining tabs.
In the Advanced tab you can add a timeout and other network related settings.
The All tab shows every property that can be set for the connection.
Once I have set the connection details as required a connection string will appear on the action window.
The connection string has now been created.
Now that I have a connection I need to execute a SQL statement to retrieve some data from the database.
The Execute SQL statement action ready to be filled in.
This particular action in PAD has a Copilot option. You can enter in natural language what you want to retrieve from the database and Copilot will attempt to generate the SQL. It should be noted that this is a preview feature and as such has limited functionality.
I am going to use the connection variable from the previous action so only need to enter the SQL statement and rename the variable holding the result of the query.
For the next part of this flow I want to test the most recent film to see if it has won any Oscars. My SQL statement should return only the details for the most recent film.
select top 1 * from film order by releasedate desc
The Execute SQL statement action will allow you to retrieve, insert, update, or delete data.
With the result of my query stored in the variable I can now close the SQL connection.
As its name suggests, this action closes the open SQL connection!
Here are the actions in the flow so far:
The flow so far will return the details for the most recent film in a SQL database called Movies, from the table called Film and store them in a variable.
A test at this point is recommended to ensure the data retrieval process has worked.
The first few columns stored in the Datatable show a single film, that at the time of writing was the most recent film.
With the details of the most recent film stored I can now test if it has won any Oscars. I will return 1 result if the test is True and another if it is False.
Add an If action to the flow. You can search for this in the Actions pane.
Searching for if returns lots of actions. The one I need is in the Conditionals section.
Using the If action will add an If block to the flow
The basic If action will perform an action/actions if the stated condition is True. I will add a False element later.
The First operand is the thing you're testing. The Second operand is the value to test against the First operand.
The Operator is how you want to compare the 2 operands. The list of Operators should cover most scenarios
In my case the First operand will be the column in the Datatable variable that holds how many Oscars the film won.
I want to test if that value is greater than zero, i.e. it did win at least 1 Oscar. If I try to do this by referring to the entire Datatable variable, things won't end well!
With the above settings the action would attempt to test the whole row's value from the Datatable.
If I did save the action, PAD would generate an error and would have to be fixed before continuing.
A nice clear error message.
To make this work, I need to refer to the row and column in the Datatable which contains the value I want to test. The column number that contains how many Oscars the film won is 15, remembering that column 1 in a Datatable has an index number of 0.
Within the % symbols I have to specify the row and column index. Row first, then column.
If the condition is True the actions between the If and End will be performed.
If the action was left in this state, should the condition be False any actions after the End would be performed.
Although I could add various actions to the If block, I will simply display a message saying the film was a winner. Again, I can refer to the relevant row and column number to return the name of the film from the Datatable variable.
A basic Display message action with the variable turned off.
The Display message action in the correct position within the If block.
I want to add a specific action should the condition evaluate to False. This requires an Else action.
I think the tooltip describes this action perfectly.
The correct placement for this action is after the Display message action but before the End of the If block.
The actions between Else and End will only be performed if the condition being tested is False.
I'll add a second Display message action to say the film is a Loser and place it in the correct position.
The full If block.
I can now run the flow to see what result I get.
The flow has paused at the False part of the If block and displayed the corresponding message.
Its worth noting that whatever the result of the If block, any actions after the End action are performed until the end of the flow.
As a test to ensure the flow is performing how I intended I could change the SQL statement to return a film that has won Oscars.
With the above SQL statement I will get the film that has won the highest number of Oscars.
I'll run the flow again to see the result.
Success! The flow has paused at the True part of the If and the message is displayed.
See the other blogs in this series for more simple PAD flows.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2025. All Rights Reserved.