ClassMethod for counting

4 views
Skip to first unread message

Dario Schmidt

unread,
Sep 10, 2005, 10:45:16 AM9/10/05
to intersystems...@info2.kinich.com
Hallo,

I written a ClassMethod with the following code to get the number of News:

ClassMethod newsAnz() As %Integer
{
&sql(DECLARE NewsCurAnz CURSOR FOR
SELECT count(titel) INTO :anz
FROM News)
&sql(OPEN NewsCurAnz)
For {
&sql(FETCH NewsCurAnz)
Quit:SQLCODE
Write anz,!
}
&sql(CLOSE NewsCurAnz)
Quit $$$OK
}

But it gives me every time a 1 and not the right result.

I use JSP and the right result can I see in the Commandline-Output. Why?

Dario



Denver

unread,
Sep 10, 2005, 11:06:56 AM9/10/05
to intersystems...@info2.kinich.com
Dario Schmidt wrote:
> SELECT count(titel) INTO :anz

Why not ID?
What exactly are you trying to count?

> Write anz,!

So you wrote it to the standard output stream.

> Quit $$$OK
But you returned 1.


So perhaps you mean
Quit anz
which returns the count as the result of the method.

Dario Schmidt

unread,
Sep 12, 2005, 4:11:54 AM9/12/05
to intersystems...@info2.kinich.com
Hallo,

ok, I have problems to understand, how the ClassMethods works. The last
version was waste.

My new version:

ClassMethod newsAnz() As %Integer
{
&sql(SELECT count(titel) INTO :anz
FROM News)
Quit anz
}
}

This works, but if I use "count(%ID)", I get 10 as result. But the right one
is 6. Do you understand this?

Many thanks.

Dario

"Denver" <ØDBraughlerØ_ØbwccØ·com> schrieb im Newsbeitrag
news:4322f...@info2.kinich.com...

Denver

unread,
Sep 12, 2005, 4:33:35 AM9/12/05
to intersystems...@info2.kinich.com
Dario Schmidt schrieb:
> My new version:
> ClassMethod newsAnz() As %Integer
> {

&sql(SELECT count(%ID) INTO :anz FROM News WHERE titel=NULL)
w " Entries with no titel = ",anz,!

> &sql(SELECT count(titel) INTO :anz FROM News)
> Quit anz
> }
>
> This works, but if I use count(%ID), I get 10 as result.
> But the right one is 6. Do you understand this?

Try SELECT COUNT(*) FROM News.
That should be the most "correct" answer.

Dario Schmidt

unread,
Sep 13, 2005, 1:50:54 PM9/13/05
to intersystems...@info2.kinich.com
Thanks


"Denver" <ØDBraughlerØ_ØbwccØ·com> schrieb im Newsbeitrag
news:43253...@info2.kinich.com...
Reply all
Reply to author
Forward
0 new messages