Show/Hide Toolbars

XSharp

NoteThis command is defined in a header file and will be preprocessed by the X# preprocessor to a function call. If you disable the standard header (-nostddefs) files then this command will not be available. If you tell the compiler to use a different standard header file (-stddef ) then this command may also be not available

Purpose

Replace fields in the current work area with values from another work area, based on the specified key value.

Syntax

UPDATE FROM <xcAlias> ON <uKeyValue> [RANDOM]REPLACE <idField> WITH <uValue>         [, <idField> WITH <uValue>...]

Arguments

FROM <xcAlias>The alias identifier for the work area used to update records in the current work area.  If there is no open database file associated with the specified alias, a runtime error is raised.

 

ON <uKeyValue>The expression that defines matching records in the FROM work area.

 

REPLACE <idField>A field in the current work area to update with a new value.

 

WITH <uValue>The value used to update the current field.  You must reference any field contained in the FROM work area with the correct alias.

 

RANDOMIf specified, the current work area must be ordered (using an index order) by <uKeyValue> but the FROM work area records can be in any order.  If not specified, both the current work area and the FROM work area must be ordered (logically or physically) by <uKeyValue>.

Description

UPDATE can only update records in the current work area with unique key values.  When there is more than one instance of a key value, only the first record with the key value is updated.  The FROM work area, however, can have duplicate key values.

 

UPDATE is functionally equivalent to DBUpdate().  

Notes

Deleted records: If SetDeleted() is FALSE, deleted records in both files are processed.  Records in the file being updated retain their deleted status and are not affected by the deleted status of records in the FROM file.

 

Visibility: If SetDeleted() is TRUE, however, deleted records are not visible and are, therefore, not processed.  Similarly, filtered records (with DbSetFilter() or a conditional controlling order) are not processed.

 

Shared mode: For a shared database, UPDATE requires a file lock on the current database file.  The FROM database file can be open in any mode.  

Examples

This example updates the CUSTOMER database file with outstanding invoice amounts:

 

USE invoices NEW
USE customer INDEX customer NEW
UPDATE FROM Invoices ON Last;
  REPLACE Owed WITH Owed + Invoices->Amount RANDOM

Assembly

XSharp.RT.DLL

See Also

DBCreateIndex(), DBUpdate(), FLock(), INDEX, JOIN, REPLACE, SetUnique(), SORT, TOTAL