Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi SQL ReplaceString (https://www.delphipraxis.net/181295-sql-replacestring.html)

danten 3. Aug 2014 17:08

Datenbank: Absolute Database • Version: 1 • Zugriff über: 1

SQL ReplaceString
 
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. :)

Dejan Vu 3. Aug 2014 20:43

AW: SQL ReplaceString
 
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.

danten 4. Aug 2014 11:12

AW: SQL ReplaceString
 
Zitat:

Zitat von Dejan Vu (Beitrag 1267409)
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

Dejan Vu 4. Aug 2014 11:24

AW: SQL ReplaceString
 
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.

danten 4. Aug 2014 11:54

AW: SQL ReplaceString
 
Zitat:

Zitat von Dejan Vu (Beitrag 1267452)
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
??????????????????????????

mkinzler 4. Aug 2014 12:40

AW: SQL ReplaceString
 
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:

SQL-Code:
update table set URL = substring ( URL,1, pos('.', URL)-1 ) || substring ( URL, pos('.', URL)+1 );


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:55 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