Skip to content

Commit da37685

Browse files
tduguidtduguid
authored andcommitted
Fixed the concat on join procedure for prefix string
1 parent 1d0c132 commit da37685

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

CS/Scripts/Formula.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ public static void PlSqlMergeValues()
13951395
Ribbon.AppVariables.ScriptRange += "MERGE INTO " + tableAlias + " AS T" + Environment.NewLine;
13961396
Ribbon.AppVariables.ScriptRange += "USING " + tableAliasTemp + " AS S" + Environment.NewLine;
13971397
Ribbon.AppVariables.ScriptRange += "ON --< Update the join to the correct unique key for the table" + Environment.NewLine;
1398-
Ribbon.AppVariables.ScriptRange += Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S") + "WHEN NOT MATCHED" + Environment.NewLine;
1398+
Ribbon.AppVariables.ScriptRange += Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S", "AND") + "WHEN NOT MATCHED" + Environment.NewLine;
13991399
Ribbon.AppVariables.ScriptRange += "THEN INSERT" + Environment.NewLine;
14001400
Ribbon.AppVariables.ScriptRange += "(" + Environment.NewLine;
14011401
Ribbon.AppVariables.ScriptRange += Ribbon.ConcatenateColumnNames(tbl.Range, "", "[", "]") + Environment.NewLine;
@@ -1406,7 +1406,7 @@ public static void PlSqlMergeValues()
14061406
Ribbon.AppVariables.ScriptRange += ")" + Environment.NewLine;
14071407
Ribbon.AppVariables.ScriptRange += "WHEN MATCHED" + Environment.NewLine;
14081408
Ribbon.AppVariables.ScriptRange += "THEN UPDATE SET" + Environment.NewLine;
1409-
Ribbon.AppVariables.ScriptRange += Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S") + "--WHEN NOT MATCHED THEN DELETE WHERE --< You may want to add a WHERE clause here" + Environment.NewLine + Environment.NewLine;
1409+
Ribbon.AppVariables.ScriptRange += Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S", ",") + "--WHEN NOT MATCHED THEN DELETE WHERE --< You may want to add a WHERE clause here" + Environment.NewLine + Environment.NewLine;
14101410
Ribbon.AppVariables.ScriptRange += "ROLLBACK;" + Environment.NewLine;
14111411
Ribbon.AppVariables.ScriptRange += "--COMMIT;" + Environment.NewLine + Environment.NewLine;
14121412
Ribbon.AppVariables.ScriptRange += "END;";
@@ -2105,7 +2105,7 @@ public static void TSqlMergeValues()
21052105
Ribbon.AppVariables.ScriptRange += "MERGE " + tableAlias + " AS T" + Environment.NewLine;
21062106
Ribbon.AppVariables.ScriptRange += "USING " + tableAliasTemp + " AS S" + Environment.NewLine;
21072107
Ribbon.AppVariables.ScriptRange += "ON --< Update the join to the correct unique key for the table" + Environment.NewLine;
2108-
Ribbon.AppVariables.ScriptRange += Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S") + "WHEN NOT MATCHED BY TARGET" + Environment.NewLine;
2108+
Ribbon.AppVariables.ScriptRange += Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S", "AND ") + "WHEN NOT MATCHED BY TARGET" + Environment.NewLine;
21092109
Ribbon.AppVariables.ScriptRange += "THEN INSERT" + Environment.NewLine;
21102110
Ribbon.AppVariables.ScriptRange += "(" + Environment.NewLine;
21112111
Ribbon.AppVariables.ScriptRange += " " + Ribbon.ConcatenateColumnNames(tbl.Range, "", "[", "]") + Environment.NewLine;
@@ -2116,7 +2116,7 @@ public static void TSqlMergeValues()
21162116
Ribbon.AppVariables.ScriptRange += ")" + Environment.NewLine;
21172117
Ribbon.AppVariables.ScriptRange += "WHEN MATCHED" + Environment.NewLine;
21182118
Ribbon.AppVariables.ScriptRange += "THEN UPDATE SET" + Environment.NewLine;
2119-
Ribbon.AppVariables.ScriptRange += Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S") + "--WHEN NOT MATCHED BY SOURCE --< You may want to add a WHERE clause here" + Environment.NewLine;
2119+
Ribbon.AppVariables.ScriptRange += Ribbon.ConcatenateColumnNamesJoin(tbl.Range, "T", "S", ", ") + "--WHEN NOT MATCHED BY SOURCE --< You may want to add a WHERE clause here" + Environment.NewLine;
21202120
Ribbon.AppVariables.ScriptRange += "--THEN DELETE" + Environment.NewLine;
21212121
Ribbon.AppVariables.ScriptRange += "OUTPUT @@SERVERNAME AS [Server Name], DB_NAME() AS [Database Name], $action, inserted.*, deleted.*;" + Environment.NewLine + Environment.NewLine;
21222122
Ribbon.AppVariables.ScriptRange += "ROLLBACK TRANSACTION;" + Environment.NewLine;

CS/Scripts/Ribbon.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,8 +1362,9 @@ public static string ConcatenateColumnNames(Excel.Range rng, string tableAliasNa
13621362
/// <param name="rng">Represents the Excel Range value</param>
13631363
/// <param name="tableAliasNameTarget">Table alias used to prefix column names</param>
13641364
/// <param name="tableAliasNameSource">Table alias used to prefix column names</param>
1365+
/// <param name="joinPrefix">Used for update or table join</param>
13651366
/// <returns>A method that returns a string of the column names</returns>
1366-
public static string ConcatenateColumnNamesJoin(Excel.Range rng, string tableAliasNameTarget, string tableAliasNameSource)
1367+
public static string ConcatenateColumnNamesJoin(Excel.Range rng, string tableAliasNameTarget, string tableAliasNameSource, string joinPrefix)
13671368
{
13681369
try
13691370
{
@@ -1372,10 +1373,10 @@ public static string ConcatenateColumnNamesJoin(Excel.Range rng, string tableAli
13721373
{
13731374
if (rng.Columns.EntireColumn[i].Hidden == false)
13741375
{
1375-
columnNames = columnNames + ", " + tableAliasNameTarget + ".[" + ((Excel.Range)rng.Cells[1, i]).Value2 + "] = " + tableAliasNameSource + ".[" + ((Excel.Range)rng.Cells[1, i]).Value2 + "]" + Environment.NewLine;
1376+
columnNames = columnNames + joinPrefix + tableAliasNameTarget + ".[" + ((Excel.Range)rng.Cells[1, i]).Value2 + "] = " + tableAliasNameSource + ".[" + ((Excel.Range)rng.Cells[1, i]).Value2 + "]" + Environment.NewLine;
13761377
}
13771378
}
1378-
columnNames = " " + columnNames.Substring(2, columnNames.Length - 2);
1379+
columnNames = new string(' ', joinPrefix.Length) + columnNames.Substring(joinPrefix.Length, columnNames.Length - joinPrefix.Length);
13791380
return columnNames;
13801381
}
13811382
catch (Exception)

0 commit comments

Comments
 (0)