A simple procedure

In the database connection point, you can define a statement for writing data to a database. Assume that the used BOD XML is the same as in the example of Reading from the database, above. So a SyncMySalesOrder BOD is sent to the database connection point.

In that case, a procedure to handle the BOD data can contain this code:

BEGIN
  -- Prevent extra result sets from interfering with SELECT statements
  SET NOCOUNT ON;

  -- Parse XML
  DECLARE @parsedXmlData int;
  EXEC sp_xml_preparedocument @parsedXmlData OUTPUT, @xmlData;

  -- Insert orders
  INSERT INTO Orders (orderNumber, orderStatus, orderDateTime, customer)
    SELECT orderNumber, orderStatus, orderDateTime, customer
    FROM OPENXML (@parsedXmlData, '/DataArea/MySalesOrder', 2)
    WITH (orderNumber   nvarchar(20) 'orderID',
          orderStatus   nvarchar(20) 'status',
          orderDateTime datetime     'orderDateTime',
          customer      nvarchar(20) 'customer')

  -- Insert lines
  INSERT INTO orderLines (orderNumber, lineNumber, item, quantity, price)
    SELECT orderNumber, lineNumber, item, quantity, price
    FROM OPENXML (@parsedXmlData, '/DataArea/MySalesOrder/MySalesOrderLine', 2)
    WITH (orderNumber  nvarchar(20) '../orderID',
          lineNumber   int          'lineNumber',
          item         nvarchar(20) 'item',
          quantity     int          'quantity',
          price        decimal      'price')
END

The procedure must have an argument to hold the data from the incoming BOD:

@xmlData XML

In ION, this statement is defined, assuming the name of the stored procedure is StoreOrders:

EXEC StoreOrders @xmlData='[Data]';

The [Data] token is a placeholder for the incoming data. At runtime this is replaced with the DataArea XML of the incoming BOD.

Note: The statement for writing the database must contain the [Data] token exactly once.