From e02b61589bcad460897b6f6da828ab950ed64dc6 Mon Sep 17 00:00:00 2001 From: Paul Mcilreavy <3075792+pmcilreavy@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:09:48 +1000 Subject: [PATCH] Add square brackets around column names --- src/Paillave.Etl.SqlServer/SqlServerSaveStreamNode.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Paillave.Etl.SqlServer/SqlServerSaveStreamNode.cs b/src/Paillave.Etl.SqlServer/SqlServerSaveStreamNode.cs index abfc91b0..a8af2c64 100644 --- a/src/Paillave.Etl.SqlServer/SqlServerSaveStreamNode.cs +++ b/src/Paillave.Etl.SqlServer/SqlServerSaveStreamNode.cs @@ -169,14 +169,14 @@ private string CreateSqlQuery(string table, List allProperties, Li StringBuilder sb = new StringBuilder(); if (pivot.Count > 0) { - var pivotCondition = string.Join(" AND ", pivot.Select(p => $"p.{p.Name} = @{p.Name}")); + var pivotCondition = string.Join(" AND ", pivot.Select(p => $"p.[{p.Name}] = @{p.Name}")); sb.AppendLine($"if(exists(select 1 from {table} as p where {pivotCondition} ))"); - var setStatement = string.Join(", ", allPropertyNames.Except(pivotsNames).Except(computedNames).Select(i => $"{i} = @{i}").ToList()); + var setStatement = string.Join(", ", allPropertyNames.Except(pivotsNames).Except(computedNames).Select(i => $"[{i}] = @{i}").ToList()); sb.AppendLine($"update p set {setStatement} output inserted.* from {table} as p where {pivotCondition};"); sb.AppendLine("else"); } var propsToInsert = allPropertyNames.Except(computedNames).ToList(); - sb.AppendLine($"insert into {table} ({string.Join(", ", propsToInsert)}) output inserted.*"); + sb.AppendLine($"insert into {table} ({string.Join(", ", propsToInsert.Select(o => $"[{o}]"))}) output inserted.*"); sb.AppendLine($"values ({string.Join(", ", propsToInsert.Select(i => $"@{i}"))});"); return sb.ToString(); }