# Set up Contact Synchronization from Microsoft SQL

Once contacts flow from Microsoft SQL into Cloud Voice, your team can dial those records straight from the Cloud Voice App. Because the synced records land in phonebooks, you can also have Cloud Voice send incoming calls from those contacts to whichever destination you choose, based on the phonebook a caller belongs to.

## Capacity limits

How many company contacts and phonebooks you can hold depends on the number of extensions on your system. Use the table below to check the ceiling for your deployment.

| Extensions (N) | N ≤ 50 | 50 < N ≤ 200 | N > 200 |
| --- | --- | --- | --- |
| Company contacts (total) | 50,000 | 200,000 | 500,000 |
| Company phonebooks | 100 | 200 | 500 |

## Before you begin

Map the contact fields you want to sync between Cloud Voice and Microsoft SQL first. See [Integrate Cloud Voice with Microsoft SQL](/pbx/integrations/microsoft-sql/integrate-cloud-voice-cloud-voice-with-microsoft-sql/#integrate-yeastar-p-series-pbx-with-microsoft-sql__section_pzg_y2z_qcc).

## Configure synchronization

1. Open the Microsoft SQL configuration page and go to the **Contacts Synchronization** section.

2. Turn on **Contacts Synchronization**, then fill in the settings described below.

   
   ![Cloud Voice, the Contacts Synchronization settings, including the target phonebook, sync frequency, feedback email, and SELECT filter](/images/pbx/mysql-contact-sync.png)

   | Setting | What it does |
   | --- | --- |
   | Synchronize to Phonebook | Choose where the synced contacts are stored. See the phonebook options below. |
   | Data Synchronization Frequency | Pick how often contacts sync, then set the time in the field that appears. |
   | Feedback Email | Optional. Enter an address to be notified of each sync result. |
   | Sync Contact Filter | Enter the `SELECT` statement that pulls contacts from Microsoft SQL. See the syntax below. |
   | Remove existing contacts which are not received from the server | When on, contacts that synced successfully last time but are missing from this run are deleted. |

   **Phonebook options for _Synchronize to Phonebook_:**

   - **Create New**: Build a brand-new phonebook to hold the synced contacts. Type its name in the **Phonebook Name** field.
   - **Read Specific Property Value and Create New**: Generate phonebooks automatically from the values in one column of your contact table. Enter that column's name in the **Property Name** field.
   - **{existing_phonebook}**: Store the contacts in an empty phonebook that already exists on the system.

   :::note
   The empty phonebooks you can pick are the ones defined under **Contacts > Phonebooks**.
   :::

   :::tip
   The **Read Specific Property Value and Create New** option is useful when you plan to route inbound calls by phonebook. For example, if a column named `belongto` labels each contact as either **Sales** or **Support**, entering `belongto` in **Property Name** tells Cloud Voice to create a **Sales** phonebook and a **Support** phonebook when you save. You can then build inbound routes that send each caller to the right team based on the phonebook match.
   :::

   :::caution
   Syncing a large number of contacts can slow the system down. Schedule the job for off-peak hours where possible.
   :::

   **Feedback email limit:** up to 5 addresses are allowed. Separate them with a semicolon (`;`).

   **Sync Contact Filter syntax:** write the statement in the form `select ${MAP} from {schema_name}.{table_name}`. For example:

   ```sql
   select ${MAP} from testpbx.contacts order by id desc
   ```

   - `select ${MAP}`, Names the database columns you want to bring into Cloud Voice. At run time, `${MAP}` is replaced by the field values that correspond to the Cloud Voice fields you enabled in the [**Map** section](/pbx/integrations/microsoft-sql/integrate-cloud-voice-cloud-voice-with-microsoft-sql/#integrate-yeastar-p-series-pbx-with-microsoft-sql__section_pzg_y2z_qcc).
   - `from testpbx.contacts`, The source table. You must use a two-part name in the form `{schema_name}.{table_name}`.
   - `order by id desc`, Sorts the results in descending order.

   :::note
   The `TOP` clause is not supported.
   :::

3. Click **Save**.

4. Click **Sync Now** to run the synchronization immediately.

   ![The Sync Now button used to pull contacts into Cloud Voice on demand](/images/pbx/mysql-contact-sync-now.png)

## What you'll see

- A banner appears showing how many contacts were synced into Cloud Voice.

  ![Confirmation banner reporting the number of contacts synchronized successfully](/images/pbx/mssql-contact-sync-success.png)

- The synced records and their phonebooks appear under **Contacts > Company Contacts / Phonebooks**, each carrying the Microsoft SQL tag ![Microsoft SQL source tag](/images/pbx/mssql-tag.png).

  ![Synced Microsoft SQL contacts and phonebooks listed under Company Contacts](/images/pbx/mssql-contact-sync.png)

- Authorized users can view and dial the contacts directly from the Cloud Voice App.

  :::note
  For this to work, grant users viewing permission on the relevant phonebook under **Extension and Trunk > Client Permission > Contact Visibility**. Users also need a Cloud Voice App that meets the minimum version for their platform:

  - iOS: version 5.7.3 or later
  - Android: version 5.7.4 or later
  - Windows desktop: version 1.7.3 or later
  - Mac desktop: version 1.7.3 or later
  :::

  ![Granting Contact Visibility permission so extension users can see a synced phonebook](/images/pbx/allow-view-mssql-phonebook.png)

## Next step

To send incoming calls to specific destinations based on the phonebook a caller belongs to, set up inbound routes that match contacts across your different phonebooks.
