Declare Function in SQL editor

When defining an action, the Declare command is used for variable declarations in the SQL editor.

In general, this command allows you to specify the name, data type and, if necessary, the initial value of a variable.

General Declare format;

DECLARE @variable_name data_type;

Specifies that a variable named @variable_name is of type data_type. data_type is a SQL data type (nvarchar, int, bit, etc.)

Value assignment can be done in two ways.

Select @variable= deger from table_name

or

the ET command is used.

SET @variable = deger.

Example1:

DECLARE @top1Product nvarchar(256)SELECT top1 @top1Product = productName from table_name 

Example2:

DECLARE @rowCount intSET @rowCount=(select count(Id) from table_name)

In these SQL code examples, two variables (@top1Product and @rowCount) are defined using the DECLARE statement and then values are assigned to these variables.

If you want to write the Declare function in the SQL Editor within the Kuika platform, you can manually enter the queries in the SQL Editor or you can get support from the Artificial Intelligence Assistant. For this, you can activate the Generate with AI switch, select the table of the Declare function you want to write and enter a prompt such as ‘write declare command in table_name table’ in the searchbox field. The artificial intelligence assistant will easily create the function for you.