Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-05-16 : 09:46:03
|
Willeus writes "I'd like to return the top N records of a table with N being passed as a parameter to the stored proc, but when I tried the following code, it was flagged as an error:SELECT TOP @N * FROM MyTable Is there another way to do this in Microsoft SQL Server 2000, besides resorting to creating a string and doing an EXEC or sp_executesql call, or using SET ROWCOUNT?I could, of course, use a temporary table with an autoincrement column, insert all the rows from MyTable into that temp table, then compare that column versus @N, but that's way too intensive especially on a table with 50,000+ records.Any other way of doing it?" |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-05-16 : 09:52:56
|
| Try set rowcount @Nselect * from ....set rowcount 0- Jeff |
 |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
|
|
|
|
|