Modifying SQL in a Word Template SQL Merge field

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

Note: 

To modify an SQL statement:

  1. Insert or modify any of these merge field types in Microsoft Word. See Inserting Merge fields in a Word template or Modifying Merge fields in a word template.
    • SQL Value
    • Table
    • List
    • Image
    • Opportunity Product Table
  2. Select the file that contains the SQL you require to modify in the list of fields, and click the SQL Ellipsis to access the Edit SQL window.
  3. Specify or modify the SELECT statement you require 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.
    • AccountManager ID: Inserts an :AccountManagerID SQL parameter. This parameter is replaced with the AccountManagerID for the contact record being merged.
    • AddressID: Inserts an :AddressID SQL parameter. This parameter is replaced with the AddressID for the contact record being merged.
    • ContactID: Inserts a :ContactID SQL parameter. This parameter is replaced with the ContactID for the contact record being merged.
    • LeadID: Inserts a :LeadID SQL parameter. This parameter is replaced with the LeadID for the lead record being merged.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
  5. Define the required field(s) after SELECT.
  6. Test the 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 data.

      1. Click OK.
      2. If you are modifying SQL for a table you are prompted to update the table columns.
        • After modifying 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 option to access the Editing Column window.
    • 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.