WHILE Loop

The WHILE loop iterates while the expression evaluates to TRUE.
With the WHILE loop you can either increment a variable or make use of a table cursor.

Syntax with table cursor:

WHILE table.EOF=false 
PRINT ‘We just read the column and got the value ‘+table.Column_name_in_table
MOVENEXT table
LOOP

Syntax with variable:

WHILE @variable<max_value PRINT ‘Variable is now ‘+@variable SET 
@variable=@variable+increment_value

LOOP

Iterating a value until condition is reached.

DECLARE @Company varchar

/* Create the internal table SalesCompanies in the InMemory data store */
IMPORT SalesCompanies=me.{SELECT 'Denmark' AS TablePrefix UNION ALL SELECT 'United States'}

/* While Loop for each company in the SalesCompanies (Denmark/United States) (see above) */
WHILE SalesCompanies.EOF=false

/* Set up the variable company */
SET @Company=SalesCompanies.TablePrefix

/* Read the data from the SQL server connection from the table substituting part of the tablename - SQL
becomes e.g. SELECT from Denmark_Sales */
IMPORT factSalesData=sqldb.{SELECT * FROM @@COMPANY_Sales}
MOVENEXT SalesCompanies / Move cursor to the next Company
LOOP /* Iterate the loop */
DECLARE @i as int

SET @i=1

WHILE @i<=10
PRINT @i
SET @i=@i+1
LOOP
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.