Home
Top.Mail.Ru Yandeks.Metrika
Forum: "Bases";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Down

The problem with the preparation of the request and its output in QReport Find similar branches


Andrey Pogorelov   (2001-12-02 10:49) [0]

There are 3 tables
Table1 Animal Registry
id
vid
category
--------------
id vid categoria
1, 1, 2
2, 1, 2
3, 2, 1
--------------
Table2 Animal Species
id
name
--------------
1, Dogs
2, Cats
--------------
Table3 - Animal Categories
id
name
--------------
1, Home
2, Homeless
--------------
It is necessary to calculate the number of animals in the database, the number of domestic and homeless species and the results put in QReport
those get in the form
Kind Homeless Homeless
Dogs 0 2
Cats 1 0
Total: 3
Help is very necessary, in advance Thank you so much.



asafr   (2001-12-03 15:14) [1]

Take TQuery, call it, for example qr_Work. You write a request: SELECT VID, CATHEGORY, COUNT (*) AS SUM_ FROM TABLE1 GROUP BY VID, CATHEGORY - you declare this qr_Work a source for QReport. Request Result:
VID CATHEGORY SUM_
1 2 2
2 1 1

In QReport in DetailBand you do this:
----------------------------------------
<- DetailHeader
VID Cathegory Sum_
----------------------------------------
<- Detail Band
[QRLabel1] [QRLabel2] [QRDBText1]
----------------------------------------
QRDBText1 - bind to the Sum_ field

In Events QRLabel1 you write: procedure TForm1.QRLabel1Print (sender: TObject; var Value: String); begin if qr_Work.FirldByName ("vid"). AsInteger = 1 then QRLabel1.Caption: = "Dogs" else QRLabel1.Caption: = "Cats" end;

Respectively procedure TForm1.QRLabel2Print (sender: TObject; var Value: String); begin if qr_Work.FirldByName ("cathegory"). AsInteger = 1 then QRLabel2.Caption: = "Home" else QRLabel2.Caption: = "Homeless" end;


Well, TOTAL: - can be found in several ways. Either use QRExpr, or on the QRDBText1Print add the Sum_ values ​​of each line. Just before printing, do not forget to do Sum _: = 0 - because then the values ​​of each printout will be added to each other.




Dick Gonsales   (2001-12-04 03:14) [2]

Request
/ * Here, depending on how you want it to look * /
/ * Variant 1 * /
SELECT T3.name, T2.name, count (T1. *)
FROM T3, T2, T1
WHERE T3.id = T1.categoria and T2.id = T1.vid
GROUP BY T3.name, T2.name
UNITY
SELECT T3.name, "Total", count (T1. *)
/ * space so that order by * works correctly * /
FROM T3, T1
WHERE T3.id = T1.categoria
GROUP BY T3.name
ORDER BY T3.name
/ * Category1 View1 qty * /
/ * Category1 View2 qty * /
/ * Category1 Total Qty * /
/ * Category2 View1 qty * /
/ * Category1 View2 qty * /
/ * Category1 Total Qty * /

/ * Variant 2 * /
SELECT T2.name, T3.name, count (T1. *)
FROM T3, T2, T1
WHERE T3.id = T1.categoria and T2.id = T1.vid
GROUP BY T2.name, T3.name
UNITY
SELECT T2.name, "Total", count (T1. *)
FROM T2, T1
WHERE T2.id = T1.vid
GROUP BY T2.name
ORDER BY T2.name
/ * View1 Category1 qty * /
/ * View1 Category2 qty * /
/ * View1 Total Qty * /
/ * View2 Category1 qty * /
/ * View2 Category2 qty * /
/ * View2 Total Qty * /



You hang up the request on Report, and paint the fields,
but in principle you can use
Delphic master to generate Report
using the SELECT described above and he will do everything for you.

The option that suggested asafr can be used
if you have few categories and types and they will not change,
because they are hard coded in code. It doesn’t matter here.



Pages: 1 whole branch

Forum: "Bases";
Current archive: 2002.01.08;
Download: [xml.tar.bz2];

Top





Memory: 0.56 MB
Time: 0.021 c
3-21973
Zav
2001-12-06 10:55
2002.01.08
DBNavigator component


14-22394
Vitaly
2001-11-09 19:51
2002.01.08
MENTA Day tomorrow ....


3-21906
Yuri Zhukov
2001-11-21 09:40
2002.01.08
Oracle ADO vs DOA - fido7.ru.delphi.db


4-22472
Eugene
2001-10-27 17:03
2002.01.08
How to make your little proxy server?


4-22508
Gluka
2001-11-06 00:18
2002.01.08
Is it possible to change the cursor over someone else's window?





afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic indonesian Irish italian Japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Spanish swahili Swedish thai turkish Ukrainian urdu vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada Khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish