You need to wrap the SELECT and FROM in a derived table and pull the WHERE to the outer query for this to work, like @Paul did in the second method in his answer.
To select first 10 elements from a database using SQL ORDER BY clause with LIMIT 10. Insert some records in the table using insert command. Display all records from the table using select statement. Here is the alternate query to select first 10 elements.
Setting up multiple parameters is very easy to do. You just need to list each parameter and the data type separated by a comma as shown below.
Add parenthesis:
SELECT TOP (@NumberOfResultsToReturn) *
SQL Server: Put the argument in parens:
SELECT TOP (@NumberOfResultsToReturn) *
Here's how I was doing it in the old times:
SET @@ROWCOUNT = @NumberOfResultsToReturn
SELECT ........
SET @@ROWCOUNT = 0
This will work, although SELECT TOP (@NumberOfResultsToReturn)
is preferable if you're using SQL server that supports this syntax:
This is supported in SQL Server 2005 and later, but not in SQL Server 2000. What version are you using?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With