Skip to content

Commit

Permalink
Merge pull request #480 from pmcilreavy/add-square-brackets
Browse files Browse the repository at this point in the history
Add square brackets around column names
  • Loading branch information
paillave authored Mar 7, 2024
2 parents 778c516 + e02b615 commit 00eb66a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Paillave.Etl.SqlServer/SqlServerSaveStreamNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ private string CreateSqlQuery(string table, List<PropertyInfo> 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();
}
Expand Down

0 comments on commit 00eb66a

Please sign in to comment.