If we want to write a stored procedure, get the top N records in the table, where n is the parameter, as an example of the Ordery table in the Northwind library, there are two ways:
The first kind is spelling SQL
Create Procedure Gettopnorders (@rowstoreTurn Int) asclare @SQL VARCHAR (8000)
Set @ SQL = 'SELECT TOP' CAST (@rowstoreturn as varchar) '* from Orders'
EXEC (@SQL)
The second is to borrow the RowCount property
Create Procedure Gettopnorders (@RowstoreTurn Int) Asset Rowcount @rowstoreTurnselection * from Orders Order by OrderID
For this example, no matter which effect is the same, but the second kind should be more flexible, just know more people!
Gettopnorders 20