1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
{$ifdef delphi6}
function PosEx(const SubString: string; const s: string; const StartIndex:integer) : integer;
begin
Result := Pos(SubString, Copy(s, StartIndex, Length(s) - StartIndex));
if Result > 0 then
Result := Result + StartIndex
end;
{$endif delphi6}
Function FoundField(SqlTxt,FieldTxt : String) : String;
var
Found : Boolean;
iStart, iStop : Integer;
begin
Result := SqlTxt;
// Enlève le superflu avant et après la zone intéressante
iStart := Pos('Select ', Result)+Length('Select ');
iStop := Pos(FieldTxt, Result)+length(FieldTxt);
Found := False;
while not(Found) do
begin
if iStop = Length(Result) Then
Found := true
else
if (result[iStop]= ' ') or (result[iStop]= ',') Then
Found := true
else
iStop := Posex(FieldTxt, Result,iStop)+length(FieldTxt)-1;
end;
Result := Copy(Result, iStart, iStop - iStart);
Found := False;
iStart := Length(Result);
While ((iStart >0) and Not(Found)) do
begin
Dec(iStart);
if Result[iStart] = ',' Then
Found := true;
end;
result :=trim(Copy(Result, iStart+1, Length(Result) - (iStart)));
result :=copy(Result,1,Pos('AS ',uppercase(Result))-1);
end;
procedure TForm1.Button1Click(Sender: TObject);
const
TabTest : array[0..3] of Record
SqlText : String;
FieldText : String;
end = (
(SqlText:'Select CodeFacture as SommeDeQte2, CodeArticle, Sum (Quantite) As SommeDeQte From [Ligne CI] Group by CodeFacture, CodeArticle';FieldText:'SommeDeQte'),
(SqlText:'Select CodeFacture, Sum (Quantite) As SommeDeQte, CodeArticle From [Ligne CI] Group by CodeFacture, CodeArticle';FieldText:'SommeDeQte'),
(SqlText:'Select Sum (Quantite) As SommeDeQte, CodeFacture, CodeArticle From [Ligne CI] Group by CodeFacture, CodeArticle';FieldText:'SommeDeQte'),
(SqlText:'Select Quantite As SommeDeQte, CodeFacture, CodeArticle From [Ligne CI] Group by CodeFacture, CodeArticleend' ;FieldText:'SommeDeQte')
);
var
i : integer;
begin
RichEdit1.Lines.Clear;
for i:=low(TabTest) to high(TabTest) do
RichEdit1.Lines.Add(FoundField(TabTest[i].SqlText,TabTest[i].FieldText));
end; |
Partager