How to make an optimized query using direct SQL statements in X++.

In this post we are going  to show you how to achieve this. As a first step we are going to create a new class and  we will proceed as always declaring the variables we are going to use.

imagen1

 

We will proceed to define the fields to be updated.  In this case they are:

–       StatusProcess

–       RecId

–       DataAreaId

imagen2

 

We will  execute the SQL statement:

imagen3

With the code below we will proceed to build our SQL string that will update the status of the fields mentioned earlier.

imagen4

We proceed to initialize the UserConnection function.

imagen5

We set the execution permissions for the SQL statements.

imagen6

We create the statement.

imagen7

We execute the statement created before with the string we build earlier.

imagen8

And finally we revoke the permissions we set before.

imagen9

And the result interpreted in SQL code is the following:

imagen10

We have shown you how to make an SQL statement in x++ code in a faster and more efficient way than the traditional one.