Run SQL Script from Workbook
To run a SQL Script from a Workbook, use the Execute SQL Script
Workbook action found in the Action list (see image below).
- Drag and drop the
Execute SQL Script
action onto the Actions list. - Optionally, add
SetParamValue()
instructions if the SQL Script is parameterized. You need oneSetParamValue(...)
pr sql parameter. - Finally, use the
Execute(...)
instruction to run the script.
Example
Suppose we have a SQL Script named "DeleteCustomer" that we want to run from a Workbook.
DELETE FROM Customers WHERE CustomerID = @CustomerID
SELECT @CustomerID AS DeletedCustomerID
Use the SetParamValue(...)
instruction to provide the customer id, and the Execute(...)
instruction to specify the name of the SQL Script to run.
SetParamValue("@CustomerID", "Customer1");
_sqlScriptResponse = Execute("DeleteCustomer");
In the example above, the SQL Script returns a value that we store in the _sqlScriptResponse
variable.
To access the value returned from the SQL Script in other Workbook component, use the Data property of the variable.
Example
ShowToastNotification('Customer ID was ' + _sqlScriptResponse.Data.DeletedCustomerID);