AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

SQL ReplaceString

Ein Thema von danten · begonnen am 3. Aug 2014 · letzter Beitrag vom 4. Aug 2014
Antwort Antwort
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#1

SQL ReplaceString

  Alt 3. Aug 2014, 17:08
Datenbank: Absolute Database • Version: 1 • Zugriff über: 1
Hi all.
How to write a SQL query to change the text in a table recursively?
Here is the code for an operation with a database table:
Delphi-Quellcode:
try
    tab_1.First;
  while not tab_1.Eof do
  begin
    with tab_1 do
    begin
      Edit;
      Application.ProcessMessages;
      Fieldbyname('URL').value := StringReplace(Fieldbyname('URL').AsString,'.','',[rfReplaceAll, rfIgnoreCase]);
      Fieldbyname('URL').value := StringReplace(Fieldbyname('URL').AsString,'/','-',[rfReplaceAll, rfIgnoreCase]);
      Fieldbyname('TEXT').value := StringReplace(tab_2.Fieldbyname('TEXT').AsString,'=','',[rfReplaceAll, rfIgnoreCase]);

      Application.ProcessMessages;
      Post;
    end;
      tab_1.Next;
    end;

  finally
    frm_convert.Caption := 'PtoP => Done';
  end;
Thank you very much in advance.
Daniel
  Mit Zitat antworten Zitat
Dejan Vu
(Gast)

n/a Beiträge
 
#2

AW: SQL ReplaceString

  Alt 3. Aug 2014, 20:43
What is recursively in your example?

Code:
update table set URL = replace (URL,'.','')
update table set URL = replace (URL,'/','-')
...
The existence and concrete syntax for 'replace' depends on the RDMS you are using (I am not familiar with ADS). Also, it might be possible to combine the replace-statements in one single update-statement.
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#3

AW: SQL ReplaceString

  Alt 4. Aug 2014, 11:12
What is recursively in your example?

Code:
update table set URL = replace (URL,'.','')
update table set URL = replace (URL,'/','-')
...
The existence and concrete syntax for 'replace' depends on the RDMS you are using (I am not familiar with ADS). Also, it might be possible to combine the replace-statements in one single update-statement.
Thanks to small changes work.
Delphi-Quellcode:
Query1.SQL.Clear;
Query1.SQL.Add('Update [tab_1] set [URL] = "REPLACE ([URL], ""."", """")"');
Query1.SQL.Add('Update [tab_1] set [URL] = "REPLACE ([URL], ""/"", ""-"")"');
Query1.ExecSQL;
......
Thanks Daniel
Daniel
  Mit Zitat antworten Zitat
Dejan Vu
(Gast)

n/a Beiträge
 
#4

AW: SQL ReplaceString

  Alt 4. Aug 2014, 11:24
Are you sure it worked? It looks as if you replace the contents of your column 'URL' with a string like 'REPLACE ([URL], ".", "")' and I doubt this is what you want.
  Mit Zitat antworten Zitat
danten

Registriert seit: 19. Feb 2012
Ort: Czech Republic, Prag
126 Beiträge
 
Delphi 10.1 Berlin Architect
 
#5

AW: SQL ReplaceString

  Alt 4. Aug 2014, 11:54
Are you sure it worked? It looks as if you replace the contents of your column 'URL' with a string like 'REPLACE ([URL], ".", "")' and I doubt this is what you want.
??????????????????????????
Delphi-Quellcode:
update produkt set URL = replace (URL,'.','');
 =>>
[4.8.2014 12:49:11] Executing Query:
update produkt set URL = replace (URL,'.','');
[4.8.2014 12:49:11] Token ',' expected, but 'replace' found at line 1, column 38 - Native error: 30222
??????????????????????????
Daniel
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#6

AW: SQL ReplaceString

  Alt 4. Aug 2014, 12:40
Absolute Database doesn't kow of an (string-)REPLACE function

http://www.componentace.com/help/abs...gfunctions.htm

If your're sure, that's only one needle:

update table set URL = substring ( URL,1, pos('.', URL)-1 ) || substring ( URL, pos('.', URL)+1 );
Markus Kinzler
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:42 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz