ken bohnenkamp
4th January 2003, 22:36
I have a table (aracp010) that is indexed by fields docn and stnl. I am trying to count the number of stnl for a given docn using SQL and then would like to display this count on a form. I can't seem to get it to work. Here is an example of what the records in the table aracp010 might look like:
DOCN STNL
0001 AEX111
0001 AEX111
0001 AEX111
0001 AEX222
0001 AEX222

In this example, the count of stnl should be 2 for docn 0001. Below is an example of the SQL I am using. Can anyone gime me some idea what I am doing wrong.

Any help would be greatly appreciated.

function count.of.detail()
{
select aracp010.docn, aracp010.stnl,
count (aracp010.stnl):count.detail
from aracp010
group by aracp010.docn, aracp010.stnl
having aracp010._index1 = :aracp009.docn

selectdo

selectempty
count.detail = 0
endselect

}

shah_bs
5th January 2003, 06:47
Try

where aracp010._index1 = {:aracp009.docn}


instead of

having aracp010._index1 = :aracp009.docn


I am assuming you have declared count.detail as an extern variable and that you are calling this function in the before.display of the count.detail field.

gfasbender
5th January 2003, 18:29
function long count.of.detail(domain tcdocn docn)
| 'tcdocn' above, should be the domain of aracp010.docn
{
long count.detail

select aracp010.docn, count(aracp010.stnl):count.detail
from aracp010
where aracp010._index1 = :docn
group by aracp010.docn
selectdo
selectempty
count.detail = 0
endselect
return(count.detail)
}

hujielilu
7th January 2003, 06:43
Hi :
I think you have to write so following:-

function count.of.detail()
{
count.detail=0
select aracp010.docn, aracp010.stnl
from aracp010
where aracp010._index1 = {:aracp009.docn}
group by aracp010.docn, aracp010.stnl
count.detail=count.detail+1
selectdo
endselect
}

so you can get what you want.