Progress
Embedded SQL-92
Guide and Reference


Using SQL for Computation

You can use an SQL SELECT statement to perform computations in an ESQL program by using the syscalctable system table for computations. This system table has owner sysprogress and contains exactly one row with a single column.

EXAMPLE

The following example illustrates using the syscalctable system table for computations.

EXEC SQL
     SELECT expression INTO :host_var FROM sysprogress.syscalctable ; 

NOTE: For a computation operation you can use any table that contains exactly one row. sysprogress.syscalctable is a table with exactly one row.

The expression in the SELECT list can contain constants or host variables and can include scalar functions.

EXAMPLE

The following examples show some of the ways you can use the SELECT statement to perform computations:

EXEC SQL BEGIN DECLARE SECTION ;
     long result ;
     long num ;
     long val ;
     DATE dtval ;
EXEC SQL END DECLARE SECTION ;
   .
   .
   .
 
EXEC SQL
     SELECT (100 * 12 (1234 - 354))
     INTO :result
     FROM sysprogress.syscalctable ;
 
 
EXEC SQL
     SELECT (:num * 10 + ABS ((360 - :val)))
     INTO :result
     FROM sysprogress.syscalctable ;
 
 
EXEC SQL
     SELECT NEXT_DAY (TO_DATE ("8/10/1998"), "WEDNESDAY")
     INTO :dtval
     FROM sysprogress.syscalctable ; 

Using the syscalctable system table provides flexibility and eases the evaluation of expressions, especially when the expressions involve values for NUMERIC, DATE, or TIME. See Appendix B, “Progress SQL-92 System Catalog Tables,” in the Progress SQL-92 Guide and Reference for information on the syscalctable system table and all system tables.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095