有沒有人知道如何在fastreport中做出不同的計數? 例 我報告:fastreport中的不同計數
Name sex
João m
João m
Maria f
在正常計數,結果將是3,但我想要一個只需要不重複的字段名稱的行數。 在這種情況下,結果將是2. 任何人都可以幫助我嗎?這只是一個例子。 我不能在SQL中做一個組,因爲我有幾個字段。
有沒有人知道如何在fastreport中做出不同的計數? 例 我報告:fastreport中的不同計數
Name sex
João m
João m
Maria f
在正常計數,結果將是3,但我想要一個只需要不重複的字段名稱的行數。 在這種情況下,結果將是2. 任何人都可以幫助我嗎?這只是一個例子。 我不能在SQL中做一個組,因爲我有幾個字段。
我不熟練使用FastReport
,但我在FastReport
的官方論壇上找到this page。
我認爲你可以通過適應你的場景來改變例子(注意,語法可能需要一些調整)。
波段:
GroupHeader1 <Sex>
MasterData1 [Name, Sex, ...]
GroupFooter1 [GetDistinctCount]
腳本(僅正在與數據集由所述字段排序來算):
var
LastValue : string;
DistinctCount : integer;
//create this event by double-clicking the event from the Object Inspector
procedure OnGroupHeader1.OnBeforePrint;
begin
if LastValue <> (<Datasetname."Sex">) then
Inc(DinstinctCount);
LastValue := <Datasetname."Sex">
end;
function GetDistinctCount: string;
begin
Result := IntToStr(DistinctCount);
end;
基部構思是,DistinctCount
變量每次遞增字段值更改。
腳本(應工作也與未分選的數據集):
var
FoundValues : array of string;
(* !!IMPORTANT!!
You need to initialize FoundValues array before to start counting: *)
SetLength(FoundValues, 0);
function IndexOf(AArray : array of string; const AValue : string) : integer;
begin
Result := 0;
while(Result < Length(AArray)) do
begin
if(AArray[Result] = AValue) then
Exit;
Inc(Result);
end;
Result := -1;
end;
//create this event by double-clicking the event from the Object Inspector
procedure OnGroupHeader1.OnBeforePrint;
begin
if(IndexOf(FoundValues, <Datasetname."Sex">) = -1) then
begin
SetLength(FoundValues, Length(FoundValues) + 1);
FoundValues[Length(FoundValues) - 1] := <Datasetname."Sex">;
end;
end;
function GetDistinctCount: string;
begin
Result := IntToStr(Length(FoundValues));
end;
基部想法是,發現每個不同的值被添加到FoundValues
陣列。
你能做到在無火鳥爲GROUP BY
:
DECLARE @T TABLE (ID INT IDENTITY (1,1), Name NVARCHAR(25) , Sex CHAR(1));
INSERT INTO @T VALUES
('Sami','M'),
('Sami','M'),
('Maria','F');
SELECT DISTINCT Name , Sex FROM @T
您還可以創建一個View
,然後在您的報告中使用它。
如果您確實需要在FastReport
中那樣做,那麼您必須使用GroupHeader
和GroupFooter
來做到這一點。
How ?
您必須在OnBeforePrint
事件中編寫腳本。
procedure OnGroupHeader1.OnBeforePrint;
通過雙擊對象檢查器中的事件創建此項。
你有SQL Server? – Sami
不... Firebird ... – sounobre