Difference between revisions of "KEYLOOKUP()"
Yvonne.milne (Talk | contribs) (→Example) |
Yvonne.milne (Talk | contribs) (→Description) |
||
Line 26: | Line 26: | ||
You should always provide a fully qualified database!table if your app is to work in Web/Mobile e.g "southwind!employees". | You should always provide a fully qualified database!table if your app is to work in Web/Mobile e.g "southwind!employees". | ||
− | |||
− | |||
Note: for Virtual Tables, see [[SQLLOOKUP()]]. | Note: for Virtual Tables, see [[SQLLOOKUP()]]. |
Revision as of 06:01, 29 October 2020
Contents
Purpose
Function to perform a cross-table lookup
Syntax
KEYLOOKUP(<workarea | alias | table>, <"indextagname">, <keyExpr>, <resultExpr> [, <notfoundExpr>])
See Also
INDEX, LOOKUP(), RLOOKUP(), SEEK(), SET RELATION, SQLLOOKUP()
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 <resultExpr> 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.
Note that in JavaScript, the <resultExpr> and <notfoundExpr> must be enclosed in quotes and passed as strings. For string expressions, this means they should be double-quoted.
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.
You should always provide a fully qualified database!table if your app is to work in Web/Mobile e.g "southwind!employees".
Note: for Virtual Tables, see SQLLOOKUP().
Example
// Lianja/VFP cLastname = keylookup("employees","employeeid",Lianja.get("page1.section1.field3").value, lastname, "not found")
// Javascript cLastname = keylookup("employees","employeeid",Lianja.get("page1.section1.field3").value, "lastname", "'not found'")
// Javascript Web Client cLastname = keylookup("southwind!employees","employeeid",Lianja.get("page1.section1.field3").value, "lastname", "'not found'")