DECLARE @p AS int
SET @p='2'
SELECT TOP(@p)*
FROM dbo.pgBakdlyDetail;
只要将变量放到圆括号内,则没有任何问题!
USE AdventureWorks2008R2; GO WITH OrderedOrders AS ( SELECT SalesOrderID, OrderDate, ROW_NUMBER() OVER (ORDER BY OrderDate) AS 'RowNumber' FROM Sales.SalesOrderHeader ) SELECT * FROM OrderedOrders WHERE RowNumber BETWEEN 50 AND 60;