How to filter compared objects using the Inc/Exc switch with the ApexSQL Data Diff CLI

Applies to
ApexSQL Data Diff

This article explains how to compare and synchronize certain objects by using switches in the CLI for ApexSQL Data Diff.

The Command Prompt has to be run as administrator so that the CLI (Command Line Interface) can be accessed with all privileges to execute any command. When it’s run, enter the exact path to the installation directory of ApexSQL Data Diff.

Entering the exact path for the installation directory

When in the installation directory, call the console application by entering the filename and extension,

Entering the filename and extension,

To compare certain objects, use the switch /inc, which will include only named objects in the comparison.

Using the /inc switch

The following example shows how to compare only two tables. There are two databases FruitImport2013 and FruitImport2014, and both of them contain four tables: Quarter1, Quarter2, Quarter3, and Quarter4. To compare tables Quarter1 and Quarter3 we’ll use the mentioned switch /inc:8:”^Quarter1$|^Quarter3$”.

Comparing tables Quarter1 and Quarter3

The full CLI argument for comparing these two tables is:
C:\Program Files (x86)\ApexSQL\ApexSQLDataDiff2014\ /d1:FruitImport2013 /d2:FruitImport2014 /inc:8:”^Quarter1$|^Quarter3$” /v /of:D:\Test\Compare.sql

Using the /exc switch

If the /exc switch is used on the same example, it will do the opposite of the /inc switch, i.e. it will exclude tables Quarter1 and Quarter3 from the comparison.

Quick tip icon

Quick tip:

The /exclude switch is processed after the /include switch (if it is sepcified)

Explaining expressions in the switch

The number 8 is a bitwise constant that represents tables in this switch. As ApexSQL Data Diff can also compare and synchronize views, so the number that represents bitwise constant for views is 4.

If an incorrect number is used, for example the number 3, it will result with the following error: “Invalid bitwise constant – 3”.

As for “^Quarter1$|^Quarter3$”, “^” is the start of the word position and “$” is the end of the word position, and the pipe character “|” separate the table names. ApexSQL Data Diff will find the whole Quarter1, or Quarter3, name instead of “SomeTextQuarter1SomeText” name.

Quick tip icon

Quick tip:

To speed up the process, and use less code in the CLI, create a project file, or an argument file, with wanted comparison and synchronization options

Last updated
March 6, 2015