Solved

ADO and Aggregate Fields

Posted on 2006-06-24
5
1,040 Views
Last Modified: 2008-01-09
Hi,

I would like to display an aggregate field using ADO.

I have an ADOTable which is the 'Item' table in my DB with primary key the "Item No". I also have another table in my DB called 'Item Ledger Entry' containing the fields "Item No", "Quantity" and primary key is the "Entry No".

I would like to display in a DBEdit the Sum of "Quantity" from the 'Item Ledger Entry' group by "Item No". My form displays the 'Item' table so all I want to do is to add this DBEdit displaying the sum of quantity for information.

Which is the quickest way to achieve this? I have thought of creating a ADOQuery having as Parameter the "Item No" which will be obtained by the DBEdit displaying this field from the 'Item' table however I am not sure this is the best way. Could u pls help me with this?
0
Comment
Question by:mc94051
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 16975428
Hi,

I would go the same way. And the query would be something like:

SELECT Sum(Quantity) FROM 'Item Ledger Entry' WHERE 'Item No' = :Param;

You may add an event handler with the query above in Item table OnScroll or if you're displaying it record by record (not in a grid) in a next/prev button click.

Regards, Geo
0
 

Author Comment

by:mc94051
ID: 16975818
Thanks Geo. I thought there was a way to avoid the query and all the fuss.
Actually my code is the one following however it does not work with the message "delphi parameter object is improperly defined". Any ideas?

  anADOQuery := TADOQuery.Create(Self);
  anADOQuery.Connection := DBConnection;
  anADOQuery.Parameters.CreateParameter('SelectedItemNo', ftString , pdInput, 10, Null);
  anADOQuery.Parameters.ParamByName('SelectedItemNo').Value := DBEdit1.Text;
  anADOQuery.SQL.BeginUpdate;
  try
    anADOQuery.SQL.Clear;
    anADOQuery.SQL.Add('SELECT [Item Ledger Entry].[Item No_], Sum([Item Ledger Entry].Quantity) AS SumOfQuantity ');
    anADOQuery.SQL.Add('FROM [Item Ledger Entry] ');
    anADOQuery.SQL.Add('GROUP BY [Item Ledger Entry].[Item No_] ');
    anADOQuery.SQL.Add('HAVING ((([Item Ledger Entry].[Item No_]) =: SelectedItemNo))');
  finally
    anADOQuery.SQL.EndUpdate;
  end;
  anADOQuery.Open;

0
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 17052114
Hi,

I cannot test anything right now but:

= :SelectedItemNo))');

there was a space between the : and the name of the parameter.

Regards, Geo
0
 

Author Comment

by:mc94051
ID: 17059210
Hi,

This is the solution but I had already found it days ago. Anyway, I 'll award you with the points since you spent your time on this
0
 
LVL 17

Expert Comment

by:geobul
ID: 17073641
Hi,

Thank you.

Regards, Geo
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question