Overview
In this document, we will learn how to create a new function in SQL and associate this new object in Wayfast. If you have to repeatedly write large SQL scripts to perform the same task, you can create a function that performs that task. Instead of rewriting the SQL, you can simply call that function.
Create a Function on SQL and link to the Project’s DB
Let’s create an easy function in SQL to establish a currency format in our application. You can follow these steps:
Define the CREATE FUNCTION statement:
-Specify a name for the function.
-Specify a name and data type for each input parameter.
-Specify the RETURNS keyword and the data type of the scalar return value.
-Specify the BEGIN keyword to introduce the function-body.
-Specify the function body. Specify the RETURN clause and a scalar return value or variable.
-Specify the END keyword.CREATE FUNCTION fn_getMoneyFormat ( @variable money ) RETURNS varchar(max) AS BEGIN DECLARE @Value varchar(max) SELECT @Value = FORMAT(@variable,'#,###.00','EN-us') --Result RETURN @Value END
Execute the CREATE FUNCTION statement
Go to Wayfast and click on “End Task” button
A popup is displayed and there’s no need to change any requirement. We are going to synchronize Wayfast to get the new function available for development.
Automatically the new function is displayed on the “Functions” section
How to associate an existing Function in Wayfast?
In case you want to include functions previously generated in the new project, we can assign the elements selecting the specific database where they are allocated and include them for development.
Turn to “Database” section and click “Functions” tab
Click “Associating Functions” button
A popup is displayed on screen. You can retrieve all the “function” objects from the specific instance and database selection. Click “Assign” button
The new object is displayed on “Functions” dashboard. In case you need to add multiple functions at the same time from one specific database, we can check “Multi Assign” checkbox
All the functions are going to be listed in the popup and ready to be checked for assignation.
In case we need to review the “Function” script in Wayfast, click “Edit Script” pencil icon and you can review the function associated to the project.
In case you have to edit the script, “Synchronize” button will establish the connection to the DB and update what we modified in Wayfast.
Recap
Wayfast brings multiple tools to develop your projects. In this document, we learnt how to create and edit function’s statements. Then we can easily synchronize the objects between database and application by selecting the correct instance.