Update Statement

OQL Update corresponds to the Update Statement of SQL-92 as below:

var

  query : IUpdateQuery;

  subQuery : ISelectQuery;

begin

  subQuery := TSelectQuery.Create;

  subQuery

    .Select(NW.Customer.CustomerID)

    .From(NW.Customer)

    .Where( OQL.Criteria(NW.Customer.ContactTitle).EQ('Owner') );

 

  query := TUpdateQuery.Create;

  query

    .Update(NW.Order)

    .Set_(NW.Order.ShipVia, 3)

    .Where( OQL.Criteria(NW.Order.CustomerID).In_( subQuery ) );

end;

== Equal to the following SQL [MS SQL Server] ==

UPDATE

  [Orders]

SET [Orders].[ShipVia] = 3

WHERE

  [Orders].[CustomerID] IN

    (

      SELECT [Customers].[CustomerID]

      FROM [Customers]

      WHERE

        [Customers].[ContactTitle] = 'Owner'

    )

Related Topics

OQL.Delphi Tutorial