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:
01148743
Vues:
16
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?


I'd say this....that assuming SQL Server 2005, I'd use the new ability to use a variable in TOP N
DECLARE @NumRecs int
SET @NumRecs = 100
SELECT TOP(@NumRecs) * FROM Person ORDER BY Age DESC
And if the teacher/recruiter said 'no', I'd slap the bejeezus out of them.

(I just had a run-in with a moronic recruiter, so I'm in a mood right now)

Kevin
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform