Hello all,

I am having a bear of a time trying to join three tables in Sybase. Here is
the query......

select DISTINCT(appl.ag_id), SUM(appl.requested) AS requested,
SUM(appl.recommend) AS recommend, SUM(appl.awarded) AS awarded, agency.agency
AS agency
from appl inner join agency on appl.ag_id = agency.ag_id
where appl.fy = '#URL.fy#'
AND agency.fy = '#URL.fy#'
AND appl.applicatio IS NOT NULL
AND appl.ho_id = '#URL.ho_id#'
AND agency.ho_id = '#URL.ho_id#'
GROUP BY appl.ag_id, agency.agency
ORDER BY appl.ag_id

In the appl table, there is a field called of_id which is a 5 char value and I
need to get the last digit which can be 1-9 which I need to cross reference
with another table to get the value's title.

This is what I was trying to do.....

select DISTINCT(appl.ag_id), SUM(appl.requested) AS requested,
grant_type.grant_type_shortcode,
SUM(appl.recommend) AS recommend, SUM(appl.awarded) AS awarded, agency.agency
AS agency
from type inner join appl on type.type_officecode on SUBSTRING(appl.of_id, 3,
4) inner join agency on appl.ag_id = agency.ag_id
where appl.fy = '#URL.fy#'
AND agency.fy = '#URL.fy#'
AND appl.applicatio IS NOT NULL
AND appl.ho_id = '#URL.ho_id#'
AND agency.ho_id = '#URL.ho_id#'
GROUP BY appl.ag_id, agency.agency
ORDER BY appl.ag_id

The problem is that with some combinations it removes the distinct process.
Thanks for any suggestion.