Board index » delphi » computed by (select sum(field))
Andreas S
![]() Delphi Developer |
Wed, 17 Mar 2004 17:09:32 GMT
|
Andreas S
![]() Delphi Developer |
Wed, 17 Mar 2004 17:09:32 GMT
computed by (select sum(field))
Hi,
I would like to know If there is a possibility to do something like alter table auftrag add sumfield computed by (sum(menge) from aufpos where Thanks for any help Andreas |
Wayne Niddery [TeamB
![]() Delphi Developer |
Thu, 18 Mar 2004 06:12:46 GMT
Re:computed by (select sum(field))Quote"Andreas S" <n...@sibbus.com> wrote in message Quote
toll on performance would be very painful. -- |
Richar
![]() Delphi Developer |
Thu, 18 Mar 2004 22:46:28 GMT
Re:computed by (select sum(field))"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote in message Quote> No. Aggregate functions like SUM cannot be part of a computed field. The I have the following computed field working perfectly well INVOICETOTAL computed by (cast((select sum(charge) from treatments where Can I expect this to fall down around my ears at some point in the future Regards Richard |
Wayne Niddery [TeamB
![]() Delphi Developer |
Thu, 18 Mar 2004 23:40:26 GMT
Re:computed by (select sum(field))Quote"Richard" <Carpente...@hotmail.com> wrote in message Quote
I would want to be very careful and would tend to do this as part of a view or proc rather than as a table definition. Of course prudent writing of select statements would only include this -- |
Richar
![]() Delphi Developer |
Sat, 20 Mar 2004 03:46:26 GMT
Re:computed by (select sum(field))"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote in message Quote> I'm open to persuasion here. <g> In our database we store all invoices created by our system. This runs into Richard |
Wayne Niddery [TeamB
![]() Delphi Developer |
Sat, 20 Mar 2004 06:11:52 GMT
Re:computed by (select sum(field))Quote"Richard" <Carpente...@hotmail.com> wrote in message Quote
sum-type field is not stored in a field at all but is queried when needed. The difference here is you will execute a single query on a patient for these (e.g.) 12 invoices, but underneath, the computed field will cause 12 identical queries - each one computing the total of those 12 invoices. I would drop the computed field and simply execute a second query that If I was really bothered by having to execute a 2nd query from the -- |
Richar
![]() Delphi Developer |
Sun, 21 Mar 2004 07:13:27 GMT
Re:computed by (select sum(field))"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote in message Quote> The difference here is you will execute a single query on a patient for The query fetches , say, 12 invoices but these 12 invoices will probably account invoice date invoicetotal <--- computed field These would then be summed at the client end by the grid. Quote> I would drop the computed field and simply execute a second query that references multiple treatments which more than likely means the invoice totals will be different for each invoice. Quote> If I was really bothered by having to execute a 2nd query from the i.e. fetch all the treatment charges belonging to invoice one and total them, then do the same for invoice two etc etc..? It just seems that having the select query that is already being used to But I'm always looking for improvements and I appreciate your input <s> Regards Richard |
Wayne Niddery [TeamB
![]() Delphi Developer |
Sun, 21 Mar 2004 09:12:00 GMT
Re:computed by (select sum(field))Quote"Richard" <Carpente...@hotmail.com> wrote in message Quote
select i.flda, i.fldb, ...i.fldn, sum(p.amount) Quote> Wouldn't the stored proc have to do exactly the same as the computed field Quote> In practice it works well and is If I find it faster you can bet I'll use it, but I suspect each individual case will need testing - as with many other things, such techniques don't work in every case. -- |
Richar
![]() Delphi Developer |
Mon, 22 Mar 2004 04:50:30 GMT
Re:computed by (select sum(field))"Wayne Niddery [TeamB]" <wnidd...@aci.on.ca> wrote in message Quote> It would also use a group by.< I'll try that to see how it performs in our app. Thanks for your suggestions Richard |
Richar
![]() Delphi Developer |
Tue, 23 Mar 2004 01:27:52 GMT
Re:computed by (select sum(field))Hello Wayne, Doing a quick test on using the group by query or the computed field seems select account, invoice, dat_, invoicetotal (computed field) from invoice 1300 records returned via IBconsole in 00:00:00:0040 the I did select account, invoice, dat_, sum(treatments.charge) from 1300 records returned in 00:00:00:220 I'm sure with suitable plans this could be tuned somewhat but the initial Regards |