?
Solved

Result of 'select count('fieldname')' in delphi?

Posted on 2003-03-03
8
Medium Priority
?
1,636 Views
Last Modified: 2008-02-26
How can I show the result of an sql-statement: select count('fieldname')from datatable
in a delphi form?
When I try it , a error message occurs that says something like: not part of an agregate function or so?
0
Comment
Question by:SCHUCla74
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 15

Expert Comment

by:VGR
ID: 8055932
I think it's an SQL error, check your syntax.
Also you may get rid of the single quotes around the field name, especially given Pascal uses single quotes for string delimiting
0
 
LVL 7

Expert Comment

by:Motaz
ID: 8055967
Which database did you use?\
If you are using MS-SQL then use:

AdoQuery11.SQL.Text:= 'select count(FieldName) from DataTable';


or
if FieldName contains spaces:

AdoQuery1.SQL.Text:= 'select count([Field Name]) from DataTable';

In Paradox:

Query1.SQL.Text:= 'select count(FieldName) from DataTable'

if FieldName is reserved word, such as Time then use this:

Query1.SQL.Text:= 'select Count(DataTable."Time") from DataTable'

Motaz
0
 
LVL 21

Expert Comment

by:ziolko
ID: 8056052
maybe simply select count(*) from DataTable.
ziolko.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:PeterLarsen
ID: 8056113
procedure TForm1.Button1Click(Sender: TObject);
begin
  Query1.Active:=false;
  Query1.SQL.Text:='select count(*) from language';
  Query1.Active:=true;
  Edit1.Text:=Query1.Fields[0].AsString;
end;


/Peter
0
 

Author Comment

by:SCHUCla74
ID: 8057015
Simply : select count(*) from DataTable is true, but must I use always a second query, or can I make like this:
select *, count(*) from Datatable ?
0
 
LVL 21

Accepted Solution

by:
ziolko earned 80 total points
ID: 8057091
select *, count(*) from DataTable will cause SQL error You can try:
select *,COUNT=(select count(*) from categories) from categories

return will be: all columns from categories and additional column filled with number of records in categories. This SQL statement is valid on MSSQL

ziolko.
0
 

Author Comment

by:SCHUCla74
ID: 8057252
I use an access database and it works without the 'COUNT='. Thank you.
0
 
LVL 15

Expert Comment

by:VGR
ID: 8059868
this doesn't at all explain why "select count('fieldname')from datatable" had failed...
0

Featured Post

Industry Leaders: 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

621 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