Subject Re: [ib-support] Limiting Record Count
Author ibrahim Bulut
We are not using Firebird.
We are using Interbase 6.0.
And we dont't think to use Interbase 6.5 about 2-3 years.

You are right.
If there are a lot of users in the same database, may be some problems.
But if we have to do it, we can find another way to do it.
We don't think to write stored procedure every limiting query.
It was only an idea.
Thanks.





Ibrahim Bulut
Software Developer
Republic of Turkey
----- Original Message -----
From: "Helen Borrie" <helebor@...>
To: <ib-support@yahoogroups.com>
Sent: Friday, April 12, 2002 4:50 PM
Subject: Re: [ib-support] Limiting Record Count


> At 04:06 PM 12-04-02 +0300, Ibrahim Bulut wrote:
> >Hi all,
> >
> >I have got a new idea.
> >I want to share my idea with mail group.
> >
> >Sometimes,
> >A lot of records fetch from query.
> >But we want first 10 record.
> >
> >I didn't do it.
> >I asked this problem to mail group, my friends.
> >But I couldn't do it.
> >
> >Some of myfriends (They are using Ms Sql Server) told me try following
sql
> >statement
> >SELECT TOP 5 * FROM TABLE
> >This sql statement fetchs only first 5 record from table1.
> >But I couldn't do it with interbase.
>
> However, you can do it with Firebird:
>
> SELECT FIRST 5 * FROM ATABLE
>
>
> >We can do it with this way in interbase.
> >Create a TEMP generator.
> >Before Execute sql statement set generator's value to 0
> >SET GENERATOR TEMP TO 0;
> >
> >And add this statement to where clause
> >(GEN_ID(TEMP,1) < 100)
> >
> >Example
> >
> >I want first 100 records from my table
> >SET GENERATOR TEMP TO 0;
> >SELECT * FROM TABLE1
> >WHERE (GEN_ID(TEMP,1) <= 100)
> >
> >another example
> >SET GENERATOR TEMP TO 0;
> >SELECT * FROM TABLE1
> >WHERE (FIELD1 BETWEEN '01.01.2001' AND '31.12.2001') AND
> > (FIELD2 STARTING '100')
> >
> >if I execute this statement 1500 records will fetch, but I want first 100
> >record.
> >I can do it with this statement
> >SET GENERATOR TEMP TO 0;
> >SELECT * FROM TABLE1
> >WHERE (FIELD1 BETWEEN '01.01.2001' AND '31.12.2001') AND
> > (FIELD2 STARTING '100') and (GEN_ID(TEMP,1) <= 100)
>
> Generators are outside transaction control, so there is nothing to stop
any
> user from calling the SET GENERATOR TEMP TO 0 statement at any
> time. Therefore, there is no way to predict what the generator's value
> would be at any given instant in time.
>
> The way to emulate Firebird's SELECT FIRST m SKIP n in a sub-v.6.5
> InterBase database, is to write a stored procedure to do the job - one
> procedure for each query from which you want some rows:
>
> create procedure GetFirst (Set_size integer, Start_row integer)
> as
> declare variable size_counter integer;
> declare variable skip_counter integer;
> declare variable..
> declare variable..
> (variables for all the cols you want in the output set)
> ;
> begin
> size_counter = 0;
> skip_counter = 0;
> for select blah from atable
> order by blah
> into :variable1, :variable2,.... do
> begin
> if (skip_counter <= :start_row) then
> skip_counter = :skipcounter + 1;
> else
> begin
> suspend;
> counter = :counter + 1;
> if (counter = :Set_size) then Exit;
> end
> end
>
> H.
>
> All for Open and Open for All
> Firebird Open SQL Database · http://firebirdsql.org ·
> http://users.tpg.com.au/helebor/
> _______________________________________________________
>
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>