Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Overview

In this lesson, we will learn how to create a new function in SQL and associate this new object in Wayfast. If we have to repeatedly write large SQL scripts to perform the same task, we can create a function that performs that task.

Let’s review how we can simply call that function instead of rewriting scripts.

Create a Function in SQL and link to the Project’s DB

First we need to create an easy function in SQL to establish a currency format in our application. We can follow these recommendations to create the function:

  1. 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.

    Code Block
    languagesql
    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
    
  2. Execute the CREATE FUNCTION statement

Go to Wayfast and click on “End Task” button

...

Automatically the new function is displayed on the “Functions” section

How to associate an existing Function in Wayfast?

In case we 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.

...

In case we have to edit the script, we can use “Synchronize” button to establish the connection to the database and update what we modified in Wayfast.

Recap

Wayfast brings multiple tools to develop our projects. In this lesson, we learnt how to create and edit function’s statements. This approach give us an easy wat to synchronize the objects between database and application selecting the correct instance.

...