procedure GenerateUpdateScriptsForOldDataCadastro;

function BytesToHex(const Bytes: TBytes): string;
var
i: Integer;
begin
Result := '';
for i := 0 to Length(Bytes) - 1 do
Result := Result + IntToHex(Bytes[i], 2);
end;

function FormatSQLValue(const Value: Variant; const FieldType: TFieldType): string;
begin
if VarIsNull(Value) then
Result := 'NULL'
else
case FieldType of
ftString, ftWideString, ftMemo, ftWideMemo, ftFixedChar, ftFixedWideChar:
Result := QuotedStr(VarToStr(Value));
ftDate, ftDateTime, ftTime:
Result := QuotedStr(FormatDateTime('yyyy-mm-dd hh:nn:ss', Value));
ftInteger, ftSmallint, ftWord, ftLargeint, ftAutoInc, ftFloat, ftCurrency, ftBCD, ftFMTBcd:
Result := VarToStr(Value);
ftBytes, ftVarBytes, ftBlob, ftGraphic, ftOraBlob, ftOraClob, ftParadoxOle, ftDBaseOle:
Result := '0x' + BytesToHex(Value);
else
Result := QuotedStr(VarToStr(Value));
end;
end;

var
QueryStore1, QueryStore2: TUniQuery;
ScriptFile, ReportFile: TextFile;
ScriptFileName, ReportFileName: string;
enderecoId, clienteId: Integer;
dataCadastro1, dataCadastro2: TDateTime;
isStore1Newer: Boolean;
FieldList: TStringList;
i: Integer;
FieldName: string;
ValueStore1, ValueStore2: Variant;
FieldType: TFieldType;
Connection: TUniConnection;
Store2Keys: TDictionary<string, TDateTime>;
CompositeKey: string;
SourceQuery, TargetQuery: TUniQuery;
begin
ScriptFileName := 'update_data_cadastro.sql';
ReportFileName := 'update_data_cadastro_report.txt';

AssignFile(ScriptFile, ScriptFileName);
Rewrite(ScriptFile);

AssignFile(ReportFile, ReportFileName);
Rewrite(ReportFile);

QueryStore1 := TUniQuery.Create(nil);
QueryStore2 := TUniQuery.Create(nil);
Store2Keys := TDictionary<string, TDateTime>.Create;

try
WriteLn(ReportFile, 'Update Scripts for endereco Records with Older data_cadastro');
WriteLn(ReportFile, 'Generated on: ' + DateTimeToStr(Now));
WriteLn(ReportFile, '--------------------------------------------------------');
WriteLn(ReportFile, '');

Connection := DM.LocalServer;

QueryStore1.Connection := Connection;
QueryStore2.Connection := Connection;

QueryStore1.SQL.Text :=
  'SELECT endereco_id, cliente_id, data_cadastro ' +
  'FROM store1.endereco';

QueryStore2.SQL.Text :=
  'SELECT endereco_id, cliente_id, data_cadastro ' +
  'FROM store2.endereco';

QueryStore1.Open;
QueryStore2.Open;

while not QueryStore2.EOF do
begin
  enderecoId := QueryStore2.FieldByName('endereco_id').AsInteger;
  clienteId := QueryStore2.FieldByName('cliente_id').AsInteger;
  dataCadastro2 := QueryStore2.FieldByName('data_cadastro').AsDateTime;

  CompositeKey := Format('%d:%d', [enderecoId, clienteId]);
  if not Store2Keys.ContainsKey(CompositeKey) then
    Store2Keys.Add(CompositeKey, dataCadastro2)
  else
    WriteLn(ReportFile, Format(
      'Duplicate key found in store2 for endereco_id=%d and cliente_id=%d.',
      [enderecoId, clienteId]));

  QueryStore2.Next;
end;

QueryStore1.First;
while not QueryStore1.EOF do
begin
  enderecoId := QueryStore1.FieldByName('endereco_id').AsInteger;
  clienteId := QueryStore1.FieldByName('cliente_id').AsInteger;
  dataCadastro1 := QueryStore1.FieldByName('data_cadastro').AsDateTime;

  CompositeKey := Format('%d:%d', [enderecoId, clienteId]);

  if Store2Keys.ContainsKey(CompositeKey) then
  begin
    dataCadastro2 := Store2Keys[CompositeKey];

    if dataCadastro1 <> dataCadastro2 then
    begin
      isStore1Newer := dataCadastro1 > dataCadastro2;

      if isStore1Newer then
      begin
        SourceQuery := TUniQuery.Create(nil);
        try
          SourceQuery.Connection := Connection;
          SourceQuery.SQL.Text := 'SELECT * FROM store1.endereco WHERE endereco_id = :id AND cliente_id = :cid';
          SourceQuery.ParamByName('id').AsInteger := enderecoId;
          SourceQuery.ParamByName('cid').AsInteger := clienteId;
          SourceQuery.Open;

          if SourceQuery.IsEmpty then
          begin
            WriteLn(ReportFile, Format(
              'Warning: Record not found in store1 for endereco_id=%d and cliente_id=%d.',
              [enderecoId, clienteId]));
          end
          else
          begin
            TargetQuery := TUniQuery.Create(nil);
            try
              TargetQuery.Connection := Connection;
              TargetQuery.SQL.Text := 'SELECT * FROM store2.endereco WHERE endereco_id = :id AND cliente_id = :cid';
              TargetQuery.ParamByName('id').AsInteger := enderecoId;
              TargetQuery.ParamByName('cid').AsInteger := clienteId;
              TargetQuery.Open;

              if TargetQuery.IsEmpty then
              begin
                WriteLn(ReportFile, Format(
                  'Warning: Corresponding record not found in store2 for endereco_id=%d and cliente_id=%d.',
                  [enderecoId, clienteId]));
              end
              else
              begin
                FieldList := TStringList.Create;
                try
                  for i := 0 to SourceQuery.FieldCount - 1 do
                  begin
                    FieldName := SourceQuery.Fields[i].FieldName;
                    if (FieldName <> 'endereco_id') and (FieldName <> 'cliente_id') then
                      FieldList.Add(FieldName);
                  end;

                  var sqlUpdate: string;
                  sqlUpdate := 'UPDATE store2.endereco SET ';

                  var SetClauses: TStringList;
                  SetClauses := TStringList.Create;
                  try
                    SetClauses.Delimiter := ',';
                    SetClauses.StrictDelimiter := True;
                    
                    for i := 0 to FieldList.Count - 1 do
                    begin
                      FieldName := FieldList[i];
                      ValueStore1 := SourceQuery.FieldByName(FieldName).Value;
                      FieldType := SourceQuery.FieldByName(FieldName).DataType;
                      
                      SetClauses.Add(Format('%s = %s', 
                        [FieldName, FormatSQLValue(ValueStore1, FieldType)]));
                    end;

                    sqlUpdate := sqlUpdate + SetClauses.DelimitedText + 
                      Format(' WHERE endereco_id = %d AND cliente_id = %d;',
                        [enderecoId, clienteId]);

                    WriteLn(ScriptFile, sqlUpdate);

                    WriteLn(ReportFile, Format(
                      'endereco_id=%d, cliente_id=%d: Updated store2.endereco (data_cadastro=%s) ' +
                      'with data from store1.endereco (data_cadastro=%s)',
                      [enderecoId, 
                       clienteId,
                       DateTimeToStr(dataCadastro2),
                       DateTimeToStr(dataCadastro1)]));
                    WriteLn(ReportFile, sqlUpdate);
                    WriteLn(ReportFile, '--------------------------------------------------------');
                  finally
                    SetClauses.Free;
                  end;
                finally
                  FieldList.Free;
                end;
              end;
            finally
              TargetQuery.Free;
            end;
          end;
        finally
          SourceQuery.Free;
        end;
      end
      else
      begin
        SourceQuery := TUniQuery.Create(nil);
        try
          SourceQuery.Connection := Connection;
          SourceQuery.SQL.Text := 'SELECT * FROM store2.endereco WHERE endereco_id = :id AND cliente_id = :cid';
          SourceQuery.ParamByName('id').AsInteger := enderecoId;
          SourceQuery.ParamByName('cid').AsInteger := clienteId;
          SourceQuery.Open;

          if SourceQuery.IsEmpty then
          begin
            WriteLn(ReportFile, Format(
              'Warning: Record not found in store2 for endereco_id=%d and cliente_id=%d.',
              [enderecoId, clienteId]));
          end
          else
          begin
            TargetQuery := TUniQuery.Create(nil);
            try
              TargetQuery.Connection := Connection;
              TargetQuery.SQL.Text := 'SELECT * FROM store1.endereco WHERE endereco_id = :id AND cliente_id = :cid';
              TargetQuery.ParamByName('id').AsInteger := enderecoId;
              TargetQuery.ParamByName('cid').AsInteger := clienteId;
              TargetQuery.Open;

              if TargetQuery.IsEmpty then
              begin
                WriteLn(ReportFile, Format(
                  'Warning: Corresponding record not found in store1 for endereco_id=%d and cliente_id=%d.',
                  [enderecoId, clienteId]));
              end
              else
              begin
                FieldList := TStringList.Create;
                try
                  for i := 0 to SourceQuery.FieldCount - 1 do
                  begin
                    FieldName := SourceQuery.Fields[i].FieldName;
                    if (FieldName <> 'endereco_id') and (FieldName <> 'cliente_id') then
                      FieldList.Add(FieldName);
                  end;

                  var sqlUpdate: string;
                  sqlUpdate := 'UPDATE store1.endereco SET ';

                  var SetClauses: TStringList;
                  SetClauses := TStringList.Create;
                  try
                    SetClauses.Delimiter := ',';
                    SetClauses.StrictDelimiter := True;
                    
                    for i := 0 to FieldList.Count - 1 do
                    begin
                      FieldName := FieldList[i];
                      ValueStore2 := SourceQuery.FieldByName(FieldName).Value;
                      FieldType := SourceQuery.FieldByName(FieldName).DataType;
                      
                      SetClauses.Add(Format('%s = %s',
                        [FieldName, FormatSQLValue(ValueStore2, FieldType)]));
                    end;

                    sqlUpdate := sqlUpdate + SetClauses.DelimitedText +
                      Format(' WHERE endereco_id = %d AND cliente_id = %d;',
                        [enderecoId, clienteId]);

                    WriteLn(ScriptFile, sqlUpdate);

                    WriteLn(ReportFile, Format(
                      'endereco_id=%d, cliente_id=%d: Updated store1.endereco (data_cadastro=%s) ' +
                      'with data from store2.endereco (data_cadastro=%s)',
                      [enderecoId, 
                       clienteId,
                       DateTimeToStr(dataCadastro1),
                       DateTimeToStr(dataCadastro2)]));
                    WriteLn(ReportFile, sqlUpdate);
                    WriteLn(ReportFile, '--------------------------------------------------------');
                  finally
                    SetClauses.Free;
                  end;
                finally
                  FieldList.Free;
                end;
              end;
            finally
              TargetQuery.Free;
            end;
          end;
        finally
          SourceQuery.Free;
        end;
      end;
    end;
  end;
  QueryStore1.Next;
end;

finally
Store2Keys.Free;
QueryStore1.Free;
QueryStore2.Free;
CloseFile(ScriptFile);
CloseFile(ReportFile);
end;

ShowMessage('Update scripts and report have been generated successfully.' + sLineBreak +
'Script File: ' + ScriptFileName + sLineBreak +
'Report File: ' + ReportFileName);
end;

----------------

Take a look at the above method: Why eventually the column "complemento" is generated like this (enclosed by double quotes):
UPDATE centauro005.endereco SET identificacao = 'Cobrança',tipo_endereco = '1',data_cadastro = '2024-04-30 10:26:01',unidade_origem = '0',logradouro = 'ROD. ARY CAMPANHOLO',numero = 'S/N',"complemento = 'KM 1,5'",bairro = 'CARDEAL',municipio = 'ELIAS FAUSTO',uf = 'SP',cep = '13350000',cod_cidade_ibge = '3514908',pessoa_responsavel = 'Gustavo',referencia = '',codigo_obra = '',endereco_ativo = 'True',end_envio_boleto = 'True',uuid_endereco = 0x0192F9A5FB347FF7A9767DD9133492C3 WHERE endereco_id = 4078 AND cliente_id = 1626;

Fix the problem regading commas inside the values that are messing with the SQL generation.