Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to get top 100 records?
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01148703
Message ID:
01148722
Vues:
17
hahaha.. I actually posted this for a friend of mine. He's doing a homework assignment and aparenlty this is what the teacher has asked for.
Personally if I was in the the class I'd use the TOP command and if the teacher graded it as an incorrect answer I'd tell them doing it any other way is stupid.


>Victor,
>
>Why can't you use the TOP clause? That would be the easiest thing. Other than that, one way (not a very pretty way mind you) that might work would be to create a table (or temp table) with that structure and a check constraint that only allowed 100 rows in the table. Then, run a INSERT INTO tempTable SELECT FROM Person ... ORDER BY age DESC. Next, you could SELECT * FROM tempTable. I'm not sure if that would work or not or what kind of multi-user issues you might run into, though. Another way would be to select the data into a cursor and then iterate the first 100 rows of the cursor, inserting the data into a table variable. Then, return a select from the table variable.
>
>Again, why can't you use the TOP clause??? :)
>
>HTH,
>Chad
>
>
>>I need a way to get the top 100 records without using LIMIT or TOP...
>>
>>something like this:
>>create table person(name varchar(30), age int);
>>
>>...and I need just the 100 oldest people... anyone know how to do this?
>>
>>Thanks!
ICQ 10556 (ya), 254117
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform