diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTask.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTask.java index cd4b3305fb9..c47cc2cd64b 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTask.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTask.java @@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.migrate.taskdef; * #L% */ +import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; import ca.uhn.fhir.jpa.migrate.JdbcUtils; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.builder.EqualsBuilder; @@ -78,7 +79,18 @@ public class AddIndexTask extends BaseTableTask { String unique = myUnique ? "unique " : ""; String columns = String.join(", ", myColumns); - String sql = "create " + unique + "index " + myIndexName + " on " + getTableName() + "(" + columns + ")"; + String mssqlWhereClause = ""; + if (myUnique && getDriverType() == DriverTypeEnum.MSSQL_2012) { + mssqlWhereClause = " WHERE ("; + for (int i = 0; i