변수를 사용한 TOP 사용

  • Post author:
  • Post category:
  • Post comments:0 Comments
  • Post last modified:November 29, 2007

SQL Server 2005에선 TOP의 값을 동적으로 결정할 수 있다. SQL Server 2000은 이 기능을 지원하지 않아서 SET ROWCOUNT를 사용하거나, 그것도 안 될 때에는 동적 쿼리를 사용했었다. 항상 아쉬워하던 기능이 제공되니 기분이 좋다.

USE AdventureWorks ;
GO
DECLARE @p AS int
SET @p='10'
SELECT TOP(@p)*
FROM HumanResources.Employee;
GO

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.