Editing SQL in a Word Template SQL Merge Field

You can use the Edit SQL dialog box to create and edit SQL statements for mail merge fields. You can insert parameters into a SQL statement and test the SQL.

Note: 

To edit an SQL statement:

  1. In Microsoft Word, insert or edit any of the following merge field types: For more information, see Inserting Merge fields in a Word template or Editing Merge Fields in a Word Template.
    • SQL Value
    • Table
    • List
    • Image
    • Mail Merge Date Stamp
    • Opportunity Product Table
  2. In the list of fields, select the file that contains the SQL you want to edit and click the SQL ellipsis button to open the Edit SQL dialog box.
  3. Specify or edit the SELECT statement you want to use to define the merge field.
  4. Click Insert Parameter.

    A list of parameters that can be added is displayed:

    • AccountID: Inserts an :AccountID SQL parameter. This parameter is replaced with the AccountID for the contact record being merged to.
    • AccountManager ID: Inserts an :AccountManagerID SQL parameter. This parameter is replaced with the AccountManagerID for the contact record being merged to.
    • AddressID: Inserts an :AddressID SQL parameter. This parameter is replaced with the AddressID for the contact record being merged to.
    • ContactID: Inserts a :ContactID SQL parameter. This parameter is replaced with the ContactID for the contact record being merged to.
    • LeadID: Inserts a :LeadID SQL parameter. This parameter is replaced with the LeadID for the lead record being merged to.
    • OpportunityID: Inserts an :OpportunityID SQL parameter. This parameter is replaced with the OpportunityID of the associated opportunity defined in the Merge With criteria for the contact record being merged to.
    • TicketID: Inserts a :TicketID SQL parameter. This parameter is replaced with the TicketID of the associated ticket defined in the Merge With criteria for the contact record being merged to.
    • UserID: Inserts an :UserID SQL parameter. This parameter is replaced with the User ID for the mail merge user.
    • ContractID: Inserts a :ContractID SQL parameter. This parameter is replaced with the ContractID of the associated contract defined in the Merge With criteria for the contact record being merged to.
    • QuoteID: Inserts a :QuoteID SQL parameter. This parameter is replaced with the QuoteID of the associated quote defined in the Merge With criteria for the contact record being merged to.
    • SalesOrderID: Inserts a :SalesOrderID SQL parameter. This parameter is replaced with the SalesOrderID of the associated sales order defined in the Merge With criteria for the contact record being merged to.
    • ReturnID: Inserts a :ReturnID SQL parameter. This parameter is replaced with the ReturnID of the associated return defined in the Merge With criteria for the contact record being merged to.
  5. After SELECT, define the required field(s).
  6. To test your SQL statement and return an example of the data:
    • Click Execute SQL.
    • Use the Lookup to select a record to use as the example>

      In the bottom pane, an example of the SQL statement displays with the selected record’s data.

      1. Click OK.
      2. If you are editing SQL for a table you are prompted to update the table columns.
        • After editing the SQL statement, if prompted to save modified properties, click Yes to save your changes, or No to discard your SQL changes.
        • If prompted to update the table heading columns, click Yes to open the Edit Table Columns dialog box and automatically update the columns listed to match the SQL query.

          The table columns must match SQL query to ensure the table displays data as expected.

        • Click the Edit Columns button to open the Edit Columns Editing Column dialog box.
    • If prompted to load columns from the SQL query, click Yes. If not prompted, click Reload to load the columns for any fields in the SQL query.