Mimer SQL User's Manual TOC PREV NEXT INDEX

Mimer Developer Site

www.mimer.com/developer


Retrieving Computed Values


You can retrieve computed values by using arithmetic and string operators in the SELECT clause of the statement.

The following computational operators may be used:

Operator
Explanation
 +
addition
 -
subtraction
 *
multiplication
 /
division
 ||
string concatenation

See the Mimer SQL Reference Manual for information regarding the type and precision of the result of an arithmetic expression.

List room prices with a 12% reduction:
 SELECT  PRICE, PRICE*0.88
 FROM    ROOM_PRICES;
Result:

 PRICE
 
 900
 792.00
 830
 730.40
 760
 668.80
 710
 624.80
 800
 704.00
 ...
 ...

Labels and Computed Values

The computed column is unnamed by default in the result table. A label may be used to provide a name:

For example:
 SELECT  PRICE, PRICE*0.88 AS SPECIAL_RATE
 FROM    ROOM_PRICES;
Result:

 PRICE
 SPECIAL_RATE
 900
 792.00
 830
 730.40
 760
 668.80
 710
 624.80
 800
 704.00
 ...
 ...

Constant Values

A column may also be 'computed' as a constant value, which adds an extra column to the result table.

For example:
 SELECT  PRICE, '12% reduction:', PRICE*0.88 AS SPECIAL_RATE
 FROM    ROOM_PRICES;
Result:

 PRICE
 
 SPECIAL_RATE
 900
 12% reduction:
 792.00
 830
 12% reduction:
 730.40
 760
 12% reduction:
 668.80
 710
 12% reduction:
 624.80
 800
 12% reduction:
 704.00
 ...
 ...
 ...

You may also retrieve a value computed using the values in two or more columns, providing that the data types are compatible.

Retrieve hotel names prefixed with the word 'HOTEL' and cities:
 SELECT  'HOTEL ' || NAME, CITY
 FROM    HOTEL;
Result:

       
  CITY       
 HOTEL LAPONIA
  STOCKHOLM  
 HOTEL SKYLINE
  UPPSALA
 HOTEL ST. GEORGE 
  STOCKHOLM  
 HOTEL Winston
  London
 HOTEL WINSTON 
  COPENHAGEN 
 HOTEL WINSTON
  GOTHENBURG 

Padding Concatenated Strings

For string concatenation, column values are padded with trailing blanks to the length of the column definition.

For example:
 SELECT  NAME || 'HOTEL', CITY
 FROM    HOTEL;
 

Result:

       
  CITY       
 LAPONIA        HOTEL
  STOCKHOLM  
 SKYLINE        HOTEL
  UPPSALA
 ST. GEORGE     HOTEL
  STOCKHOLM  
 Winston        HOTEL
  London
 WINSTON        HOTEL
  COPENHAGEN 
 WINSTON        HOTEL
  GOTHENBURG 

Parentheses

When retrieving computed values, parentheses can be used to force the operation priority.

Without parentheses, the normal precedence rules for arithmetic apply, i.e. multiplication and division are performed before addition and subtraction, and operators with the same precedence are evaluated from left to right.



Upright Database Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40
dbtechnology@upright.se
Mimer SQL User's Manual TOC PREV NEXT INDEX