有没有人知道如何在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