?
Solved

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

Posted on 2003-03-03
8
Medium Priority
?
1,535 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
[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
  • 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
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!

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

762 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