# Using Global Variables with SQL

Inaport has the ability to store information on disk in between import operations, using Global Variables. Global variables are created and accessed using the gloXXX() functions.

The advantage of global variables is that they are stored to disk between import operations, which means that they can be accessed in the next operation.

### Why is this useful?

Imagine you are updating GoldMine with accounting information. You might store the number of the last invoice processed during the import run in a global number variable called "lastInvNo".

This global variable can then be accessed from the SQL SELECT statement, using the glonum() function. This means that it can be used in the WHERE clause of the SELECT:

SELECT * FROM Invoices WHERE InvNo > glonum("lastInvNo")

The 'glonum("lastInvNo")' will be replaced with the value of the lastInvNo variable, and this value will then be used in processing the SQL statement. the result is that only invoices greater than the last processed invoice number will be retrieved.

### How does it work?

When you define a data source for Inaport, you can use an SQL SELECT statement to pull records from the source.

Inaport will examine the SQL statements before getting the records, and will replace all occurrences of a gloXXX() expression with the value of the variable. For example, suppose that the value of the variable "lastinvNo" was 1234.

When the expression above is evaluated, 'glonum("lastInvNo")' will be replaced with '1234'. The new expression with then read:

SELECT * FROM Invoices WHERE InvNo > 1234

and this is what is then sent to the source database.