Example 1: Connect to database and update the records based on the user input
- Open the Task Editor from Tools -> Task Editor.
- Double click on the 'Database' command.
- Select the 'Connect' option
- Specify the database you want to connect to by clicking on '...' button.
- Test the connection before you save the command.
- Similarly insert a Database->Insert/Update/Delete command with the appropriate SQL statement.
- Insert a Database->Disconnect command.
- Tip: The Insert/Update/Delete statement can have variables and the values of those
variables can be taken from the user using the 'Prompt' command.
Example 2: Query all the accounts whose revenue is over 1 million dollar and print the account names to an Excel file.
- Open the Task Editor from Tools -> Task Editor.
- Double click on the 'Database' command.
- Select the 'Connect' option
- Specify the database you want to connect to by clicking on '...' button.
- Test the connection before you save the command.
- Similarly insert a Database->Select Query command with the appropriate SQL statement to get all required accounts.
- Insert a Database->Disconnect command.
- To access the result returned by the SQL Query, use
the $Dataset Column$ System variable provided by Automation Anywhere. Use Loop
for Each row in a SQL query dataset option to loop through all the rows of the
SQL Query result. To access each column use $Dataset Column(index)$ for e.g. to get
the first column use $Dataset Column(1)$.
Example 3: Connect to database and create tables, drop tables, alter tables.
- Open the Task Editor from Tools -> Task Editor.
- Double click on the 'Database' command.
- Select the 'Connect' option
- Specify the database you want to connect to by clicking on '...' button.
- Test the connection before you save the command.
- Similarly insert a Database->Insert/Update/Delete command with the appropriate SQL statement to create, drop, alter tables etc.
- Insert a Database->Disconnect command.
Example 4: Connect to
database and call a procedure stored in the database to update records based on the user input
- Open the Task Editor from Tools -> Task Editor.
- Double click on the 'Database' command.
- Select the 'Connect' option
- Specify the database you want to connect to by clicking on '...' button.
- Test the connection before you save the command.
- Similarly insert a Database->Run Stored Procedure command with the procedure name and parameters, if any. The procedure specified should have
already been created in the database.
- Insert a Database->Disconnect command.
- Tip: The procedure name as well as the parameters can have variables and the values of those variables can be taken from the user using the 'Prompt' command.
Examples of SQL Queries
- To query all the columns from a table called Table1, use the query 'Select * From Table1'
- To query FirstName and LastName from a table called Names use the query
'Select FirstName, LastName from Names'
- To query FirstName and LastName from a table called Names where FirstName
is 'John' use the query Select FirstName, LastName from Names WHERE FirstName='John'