[DUG] Sorting by date
Charlie
kerscher at bellsouth.net
Thu Jun 2 10:08:36 NZST 2011
Hi, I'm using Delphi 2007 and dBase files. I am creating a .csv file. I
need to sort my file by RailType and OrderDate. The resultant .csv shows
RailType is in alpha order and OrderDate is in "string" order; namely,
the sort is on the month part of the date ( 12/2/2010) that is the 12.
So I'm getting 1/6/2011 before 12/6/2010. I need to have last year's
dates appear before this years dates. Hope that makes sense.
When I'm debugging, if I remember correctly, the date appears as a
numeral. Would the numeral representation for 12/6/2010 be smaller than
the numeral for 1/6/2011. If so could I somehow use that for sorting
(ordering in the query)?
Thanks so much for your thoughts.
Charlie
I am creating a .csv file as follows:
FilePath := ExtractFilePath(Application.EXEName);
if FilePath[Length(FilePath)] <> '\' then
FilePath := FilePath + '\';
FilePath := FilePath + 'csv\';
ForceDirectories(FilePath);
AssignFile(F, FilePath + Format('%s.csv',['Item Size List '+sDate]));
Rewrite(F);
Writeln(F, Format ('%s,%s,%s,%s,%s,%s,%s,%s,%s',
['WIP #',
'Dealer',
'Customer',
'Order Date',
'Invoice Date',
'Item',
'Width',
'Depth',
'Rail'
]));
qItems.First;
{2011.6.1 changed Price to Rail above and sPrice to
qItemsRailType.AsString below}
rcount := qItems.RecordCount;
for I := 0 to rcount - 1 do
begin
for j := 1 to length (sLoc) do if ( sLoc[j] = ',' ) then sLoc[j]
:= #32;
sInvDate := '';
sPrice := Format('%2.2f',[qItemsPrice.AsFloat]);
Writeln(F, Format ('%s,%s,%s,%s,%s,%s,%s,%s,%s',
[ qItemsDBANumber.AsString,
qItemsCustomer.AsString,
qItemsDealer.AsString,
DateToStr(qItemsOrderDate.Value),
sInvDate,
qItemsItem.AsString,
qItemsMMWidth.AsString,
qItemsMMDepth.AsString,
qItemsRailType.AsString
]));
qItems.Next;
end;
//DateToStr(qItemsCompDate.Value),
CloseFile(F);
My query is:
Select oe.DBANumber, oe.CompDate, oe.OrderDate, oe.Type,
gendet.Dealer, gendet.Customer, gendet.Item,
gendet.MMWidth, gendet.MMDepth, gendet.Price,
gendet.RailType
From oe inner join gendet
on oe.number = gendet.number
where Trim(oe.ID) =:sID
and oe.CompDate is null
and oe.OrderDate between :Beg_Date and :End_Date
and oe.Type not in ("C","I","Q")
Order by gendet.RailType, oe.OrderDate
More information about the Delphi
mailing list