COGNOiSe.com - The IBM Cognos Community

General Discussion => General Discussion & Gossip => Topic started by: pyne on 28 Sep 2005 07:37:58 AM

Title: Counting Rows
Post by: pyne on 28 Sep 2005 07:37:58 AM
Hi,
Ã,  Ã,  Ã,  Ã,  I'm totally lost trying to find a way of counting the number of rows or records that reside in a table.  I need to do this, and assigning the value returned to a define or temporary variable.
I hope this makes sense, and that someone can help me.
Title: Re: Counting Rows
Post by: CoginAustin on 28 Sep 2005 09:04:36 AM
This is gossip?

Please post in the appropriate place so we know what your asking and how to answer. Thanks

Title: Re: Counting Rows
Post by: pyne on 28 Sep 2005 09:27:07 AM
I'm sorry, but it's not entirely obvious to me where else I could have posted my question.  Could you tell me the right place?
Title: Re: Counting Rows
Post by: CoginAustin on 28 Sep 2005 12:42:17 PM
Well, I am not sure either..lol

What program are you trying to get a count out of?

Title: Re: Counting Rows
Post by: pyne on 29 Sep 2005 02:28:45 AM
I'm designing a screen in quick / qdesign, and I'm accessing an SQL database.Ã,  What I need is a unique number for the primary key, and I thought, 'what better than the number of records in the table'.Ã,  I know there is a way of having the primary key increment itself as new records are entered, but the table was not originally set up that way, and I don't have the permissions to modify it.Ã,  Is there a way to count the rows? ???
Title: Re: Counting Rows
Post by: Vaughn on 14 Oct 2005 08:35:23 AM
I would be hesitant to use the number of rows for a unique number,
especially with a SQL database.  (Multi-user, anyway.)  If you
can't create a view "SELECT COUNT(*) FROM THE_TABLE", which
would be a read-only access, then
you would be forced to set up an internal procedure:

proc internal count_em_up
begin
let t_count = 0
while retrieving THE_TABLE sequential ;need to lock up THE_TABLE to be sure
  let t_count = t_count + 1
end

If you have lots of rows, you need to lock this for a long time.
I recently had a similar requirement.  I needed a unique sequence
number for printing.  I set up a new table with the number field in
it.  Now I lock this small table, get the value, use it, increment it
and update the table.  Nice short locking.
If you really need a unique key and your data access fields don't
give it to you, why don't you go to the system clock for a unique number?
Some sort of getsystemval should work for you.  What system are
you using?  I have only seen QUICK with OpenVMS so I can't really
give a detailed answer except with that platform.