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

Distinct Count



Hello!

I have a problem, which may be more of a SQL issue than SQR, but I thought
maybe someone could help.   I want to count the number of different periods
from a table for each employee and then perform some calculations based on
the number.

This is my procedure:
begin-procedure count-periods
 let #count_period = 0
begin-select distinct
count(eb.balance_period)  &count_period
     let #count_period = &count_period
 from ps_earnings_bal eb
 where eb.emplid = &a.emplid
  and eb.grs_mtd > 0
  and eb.spcl_balance = 'N'
  and eb.balance_id = 'CY'
  and eb.balance_year = '1998'
end-select
end-procedure

The problem is:  This exists in the table: 1,1,2,2,2,3.  I would expect the
above procedure to give me a count of 3, yet the result is 6.

I have an ORACLE database and am using SQR3.

Any help would be greatly appreciated.

Thanks, Kathy