[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Re: SQL Count Statement



> Can you include an SQL count statement in your SQR without having any
> other columns being selected?
>
> Begin-SQL
> Select count (emplid) from ps_employees
> where empl_status in ('A','L')
> order by paygroup
> End-SQL

Yes.  However, you will need to use "begin-select" instead of "begin-sql",
and you will probably want to give SQR an explicit name for the associated
host variable so that you can refer to the count easily later in your
program.

For example:

begin-select
count(emplid)  &emplid_count
where empl_status in ('A', 'L')
end-select
[...]
show &emplid_count


Note that "order by" won't do anything in this case because the count
is the same regardless of the order.  If you wanted to get a count of the
number of employees in each paygroup, you could do this with a "group by",
but then you'd almost certainly want to select paygroup column as well so
you would know which paygroup's count you were processing.


                                                Nathan
----------------------------------------------------------------------------
Nathan Treadway    | Ray Ontko & Co. | info@ontko.com (auto-reply server)
nathant@ontko.com  | Richmond, IN    | ftp.ontko.com, http://www.ontko.com/