"Abhi" <getabhijit (AT) indiatimes (DOT) com> wrote
Quote:
Hi
I want a query which will return first n records from a table
in Sybase.
I do not want to use the SET Rowcount option. Can anybody suggest me
the
solution for the same.
Thanks and Regards
-Abhi |
I also think you should simply use 'set rowcount'. But if you don't
want to do that (tell us why...) this is an alternative:
select row_number = identity(9), * into #t from your_table order by
<your-ordering-criterium>
select * from #t where row_number <= N -- N = a number defined by
you
Note the the whole concept of 'the first N rows' is rather shaky
without defining the what ordering you have in mind. Hence, you should
provide an 'order by' to define this.
Also note that this is not advisable when the table in question is
large.
HTH,
Rob
-------------------------------------------------------------
Rob Verschoor
Certified Sybase Professional DBA for ASE 12.5/12.0/11.5/11.0
and Replication Server 12.5
Author of "Tips, Tricks & Recipes for Sybase ASE" and
"The Complete Sybase ASE Quick Reference Guide"
Online orders accepted at http://www.sypron.nl/shop
mailto:rob (AT) DO (DOT) NOT.SPAM.sypron.nl.REMOVE.THIS.DECOY
http://www.sypron.nl
Sypron B.V., P.O.Box 10695, 2501HR Den Haag, The Netherlands
-------------------------------------------------------------