Subject | Re: Retrieving non-column data under program control |
---|---|
Author | Adam |
Post date | 2005-05-31T23:18:14Z |
--- In firebird-support@yahoogroups.com, "Alan Jones" <AlanJones@s...>
wrote:
The easiest (and conveniently also the safest way) is to name the field
something using the "[expression] AS [to be called]" syntax.
Using your example:
SELECT COUNT(*) AS CNT FROM mytable;
Then you just do whatever you would normally do to retrieve a field
named CNT.
I know some people have been burnt in the past by presuming that the
field will be called F_1 or something like that, so by explicitly
naming the field, you don't risk anything like that.
This is also useful if your query joins two (or more) tables with
identically named fields and you are interested in both.
eg:
select e.name as EmployeeName, s.name as SiteName
from employee e
join site s on (e.siteid = s.id)
where ....
Hope that helps
Adam
wrote:
> My application is written C++. I can retrieve column information butretrieve
> when I do a SELECT that returns a number, I don't know how to
> it. An example is:Hi Alan,
>
> SELECT COUNT(*) FROM mytable;
>
> Can someone point me in the right direction?
>
> Alan
The easiest (and conveniently also the safest way) is to name the field
something using the "[expression] AS [to be called]" syntax.
Using your example:
SELECT COUNT(*) AS CNT FROM mytable;
Then you just do whatever you would normally do to retrieve a field
named CNT.
I know some people have been burnt in the past by presuming that the
field will be called F_1 or something like that, so by explicitly
naming the field, you don't risk anything like that.
This is also useful if your query joins two (or more) tables with
identically named fields and you are interested in both.
eg:
select e.name as EmployeeName, s.name as SiteName
from employee e
join site s on (e.siteid = s.id)
where ....
Hope that helps
Adam