From 266cc2fe88106ddad046f6dfc8e3d6ed933bc5ab Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Wed, 10 Feb 2021 16:10:03 +0100 Subject: [PATCH] Use coalesce instead of iif (fixes #77) --- SyncChanges.Tests/Tests.cs | 1 + SyncChanges/Synchronizer.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/SyncChanges.Tests/Tests.cs b/SyncChanges.Tests/Tests.cs index 82977ed..0124dca 100644 --- a/SyncChanges.Tests/Tests.cs +++ b/SyncChanges.Tests/Tests.cs @@ -40,6 +40,7 @@ private static void CreateDatabase(string name) using (var db = GetDatabase()) { db.Execute($"create database [{name}]"); + db.Execute($"alter database [{name}] set COMPATIBILITY_LEVEL = 100"); db.Execute($"alter database [{name}] set CHANGE_TRACKING = ON (CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON)"); if ((string)TestContext.CurrentContext.Test.Properties.Get("snapshot") != "off") { diff --git a/SyncChanges/Synchronizer.cs b/SyncChanges/Synchronizer.cs index a47b729..417d3f5 100644 --- a/SyncChanges/Synchronizer.cs +++ b/SyncChanges/Synchronizer.cs @@ -203,7 +203,7 @@ private IList GetTables(DatabaseInfo dbInfo) { using (var db = GetDatabase(dbInfo.ConnectionString, DatabaseType.SqlServer2008)) { - var sql = @"select TableName, ColumnName, iif(max(cast(is_primary_key as tinyint)) = 1, 1, 0) PrimaryKey from + var sql = @"select TableName, ColumnName, coalesce(max(cast(is_primary_key as tinyint)), 0) PrimaryKey from ( select ('[' + s.name + '].[' + t.name + ']') TableName, ('[' + COL_NAME(t.object_id, a.column_id) + ']') ColumnName, i.is_primary_key