ADO.NET Provider for FinancialForce

Build 21.0.7929

UPSERT ステートメント

An UPSERT statement updates an existing record or creates a new record if an existing record is not identified.

Configuring Upserts

Upserts can only be performed on a field explicitly defined in FinancialForce to be an external key. You need to provide the name of this field in a column called ExternalIdColumn, as shown in the following query:

  UPSERT INTO Lead (FirstName, LastName, Company, External_Id_Column__c, ExternalIdColumn) 
  VALUES ('Bob', 'Thorton', 'Universal Pictures', 12345, 'External_Id_Column__c')

In order for the ExternalIdColumn to show up, modify the FinancialForce connection properties to set the PseudoColumns field to the value '*=*' without the quotes.

An UPSERT statement updates an existing record or create a new record if an existing record is not identified.


The UPSERT syntax is the same as for insert. FinancialForce uses the input provided in the VALUES clause to determine whether the record already exists. If the record does not exist, all columns required to insert the record must be specified. See データモデル for any table-specific information.

UPSERT INTO <table_name> 
( <column_reference> [ , ... ] )
( { <expression> | NULL } [ , ... ] ) 

<expression> ::=
  | @ <parameter> 
  | ?
  | <literal>

You can use the ExecuteNonQuery method to execute data manipulation commands and retrieve the rows affected, as shown in the following example:


String connectionString = "User=myUser;Password=myPassword;Security Token=myToken;";
int rowsAffected;
using (FinancialForceConnection connection = new FinancialForceConnection(connectionString)) {
  FinancialForceCommand cmd = new FinancialForceCommand("UPSERT INTO Account (Name) VALUES ('John')", connection);
  rowsAffected = cmd.ExecuteNonQuery();


Dim connectionString As [String] = "User=myUser;Password=myPassword;Security Token=myToken;"
Dim rowsAffected As [Integer]
Using connection As New FinancialForceConnection(connectionString)
  Dim cmd As New FinancialForceCommand("UPSERT INTO Account (Name) VALUES ('John')", connection)
  rowsAffected = cmd.ExecuteNonQuery()
End Using

Retrieving Generated Ids

To retrieve the Id of the last inserted record, use the SCOPE_IDENTITY function, as shown in the following example:


  cmd = connection.CreateCommand();
  cmd.CommandText = "SELECT SCOPE_IDENTITY()";
  Object returnedValues = cmd.ExecuteScalar();
  String Id = (String)returnedValues;

  cmd = connection.CreateCommand()
  cmd.CommandText = "SELECT SCOPE_IDENTITY()"
  Dim returnedValues As [Object] = cmd.ExecuteScalar()
  Dim Id As [String] = returnedValues

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7929