Thema: Delphi SQLCmd Manipulation

Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#4

AW: SQLCmd Manipulation

  Alt 31. Jul 2013, 11:06
Ganz simpel und einfach?

Delphi-Referenz durchsuchenStringReplace

SQL-Code:
SELECT A.ID, (SELECT FIRST 1 B.ID FROM TABB B WHERE B.X = A.X)
, A.TEST
FROM TABA A
WHERE (%WHEREADD%) AND (A.ID IN (SELECT C.ID FROM TABC C WHERE C.Y = A.Y) AND A.DELETED = 0)
UNION
SELECT D.ID, (SELECT FIRST 1 B.ID FROM TABB B WHERE B.X = D.X)
, D.TEST
FROM TABD D
WHERE (%WHEREADD%) AND (D.ID IN (SELECT C.ID FROM TABC C WHERE C.Y = D.Y) AND D.DELETED = 0)
Delphi-Quellcode:
function ModifyWhereAdd(const SqlCmd, WhereAdd : string) : string;
var
  LReplacePattern : string;
begin
  if ( WhereAdd = '' ) then
    LReplacePattern := '1=1'
  else
    LReplacePattern := WhereAdd;

  Result := StringReplace( SqlCmd, '(%WHEREADD%)', '( ' + LReplacePattern + ' )', [ rfReplaceAll, rfIgnoreCase ] );
end;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat