OP Many to one join

4D - Documentation   Français   English   German   4D Open for 4D, Command Theme List   4D Open for 4D, Command Alphabetical List   Back   Previous   Next

version 1.5


OP Many to one join (connectionID; manyTableID; oneTableID) Longint

ParameterTypeDescription
connectionIDLongintConnection ID with target server
manyTableIDLongintNumber of the Many file in the database
oneTableIDLongintNumber of the One file in the database
Function resultLongintError code result for the function

Description

OP Many to one join creates a new selection of records in oneTableID based on the selection of records in manyTableID. For example, if you have a selection of records in the many table, you can retrieve the records in the One table that are related to that selection.

This command can work across several levels of relations. For example, according to the [Customers]/ [Invoices] table structure, a call to OP Many to one join with the Many file [Invoices] and the One file [Customers] selects the customers related to the selected records in [Invoices].

OP Many to one join works with both manual and automatic relations.

Error Codes

If OP Many to one join executes successfully, it returns 0. Otherwise, this function returns one of the following errors:

Error CodeDescription
-9972Table number is out of range.
10128The 4D Open for 4th Dimension package has not been initialized.
10136The connection does not exist.
10154This command cannot be executed right now.

Example

This example prints a list of the customers who received the 10 largest invoices for the current year:

   C_LONGINT(vRecords; $ErrCode)
   C_STRING (10;vValue)
   C_LONGINT(vTableInvoices;vTableCustomers;vFieldDate;vFieldAmount;vFieldRef)

   $errCode:=OP Get one field number (vConnectID;"[Invoices]Invoice date";vTableInvoices;vFieldDate)   
   $errCode:=OP Get one field number (vConnectID;"[Invoices]Invoice amount";vTableInvoices;vFieldAmount)
   $errCode:=OP Get one field number (vConnectID;"[Customers]Ref";vTableCustomers;vFieldRef)
   
      `Compute this year's 1st of january
   vValue:="01/01/" + String ( Year of ( Current date ) ;"####") 
 
      ` Query for this year's invoices
   $errCode:=OP Single query (vConnectID;vTableInvoices;vFieldDate;">";->vValue;vRecords)

      `Order by decreasing amount (largest amount is first of selection)
   $errCode:=OP Single order by (vConnectID;vTableInvoices;vFieldAmount;"<") 
   
      ` Focus on the 10 largest invoices
   $errCode:=OP Reduce selection (vConnectID;vTableInvoices;10)

      ` Create a selection of customers for those invoices
   $errCode:=OP Many to one join (vConnectID;vTableInvoices;vTableCustomers)

      ` Find out how many customers in the new selection
   $errCode := OP Records in selection (vConnectID;vTableCustomers;vRecords)
   ALERT (" This year's top ten invoice correspond to " + String (vRecords) + " customers")

   PrintCustomers

See Also

OP One to many join, OP Records in selection, RELATE ONE SELECTION.


4D - Documentation   Français   English   German   4D Open for 4D, Command Theme List   4D Open for 4D, Command Alphabetical List   Back   Previous   Next