Difference between revisions of "KEYLOOKUP()"

From Lianjapedia
Jump to: navigation, search
Line 3: Line 3:
  
 
==Syntax==
 
==Syntax==
KEYLOOKUP(<workarea | alias | table>, <"indextagname">, <keyExpr>, <valueExpr>)
+
KEYLOOKUP(<workarea | alias | table>, <"indextagname">, <keyExpr>, <valueExpr> [, <notfoundExpr>])
  
 
==See Also==
 
==See Also==
Line 9: Line 9:
  
 
==Description==
 
==Description==
The KEYLOOKUP() function looks up the specified index <keyExpr> in the index <indextagname> of the specified <workarea | alias | table>.  The KEYLOOKUP() function then evaluates the expression <valueExpr>, and returns the value of the <valueExpr> if the <key expression> is found.  The KEYLOOKUP() function returns a null string if the <key expression> is not found.  
+
The KEYLOOKUP() function looks up the specified index <keyExpr> in the index <indextagname> of the specified <workarea | alias | table>.  The KEYLOOKUP() function then evaluates the expression <valueExpr>, and returns the value of the <valueExpr> if the <key expression> is found.  The KEYLOOKUP() function returns a null string if the <key expression> is not found or the <notfoundExpr>, if specified.
  
 
The current record position in the specified <workarea | alias | table> cursor is not moved so this function can also safely be used in SQL queries.  
 
The current record position in the specified <workarea | alias | table> cursor is not moved so this function can also safely be used in SQL queries.  
Line 23: Line 23:
 
open database southwind
 
open database southwind
 
use orders in 0
 
use orders in 0
? keylookup("employees","employeeid",orders.employeeid, employees.lastname)
+
? keylookup("employees","employeeid",orders.employeeid, lastname, "not found")
 
</code>
 
</code>
  

Revision as of 08:47, 30 April 2013

Purpose

Function to perform a cross-table lookup

Syntax

KEYLOOKUP(<workarea | alias | table>, <"indextagname">, <keyExpr>, <valueExpr> [, <notfoundExpr>])

See Also

LOOKUP(), RLOOKUP(), SEEK(), SET RELATION

Description

The KEYLOOKUP() function looks up the specified index <keyExpr> in the index <indextagname> of the specified <workarea | alias | table>. The KEYLOOKUP() function then evaluates the expression <valueExpr>, and returns the value of the <valueExpr> if the <key expression> is found. The KEYLOOKUP() function returns a null string if the <key expression> is not found or the <notfoundExpr>, if specified.

The current record position in the specified <workarea | alias | table> cursor is not moved so this function can also safely be used in SQL queries.

If the specified table is not already open then Lianja will open the table automatically.

This function can be used to dynamically lookup foreign key values in target tables.

It can also be used to lookup NoSQL key/value pairs.

Example

open database southwind
use orders in 0
? keylookup("employees","employeeid",orders.employeeid, lastname, "not found")