Declare Function in SQL Editor

On the Kuika platform, you can define a variable using the “DECLARE” command in the SQL Editor. This command allows you to specify the name of a variable, its data type and, if necessary, its initial value.

General DECLARE Format

DECLARE @variable_name data_type;
  • Here, a variable named @variable_name is declared with the specified data_type. data_type is the SQL data type (for example, nvarchar, int, bit, etc.).

Value Assignment Methods

There are two ways to assign a value to a variable:

1. SELECT Assignment:

SELECT @variable = değer FROM table_name;

2. Assignment with SET:

SET @variable = değer;

Example 1:

DECLARE @top1Product nvarchar(256);SELECT TOP 1 @top1Product = productName FROM table_name;
  • In this example, a variable named @top1Product is declared and the first product name from table_name is assigned to this variable.

Example 2:

DECLARE @rowCount int;SET @rowCount = (SELECT COUNT(Id) FROM table_name);
  • In this example, a variable named @rowCount is defined and the total number of rows in table_name is assigned to this variable.

DECLARE Usage on Kuika Platform

On the Kuika platform, you can manually type the “DECLARE” command in the SQL Editor or you can get support from the Artificial Intelligence Assistant.

By activating the “Generate with AI” switch, you can enter a command by specifying the relevant table in the Search Box field. For example:

  • "I want to list only active departments, write a DECLARE command about it ”. The AI will automatically generate the relevant DECLARE function.

In this way, you can create your query quickly and easily.