SQL Server 2005 introduced new TOP behavior - like TOP function supports variables and expressions.
As a result it is possible to use a subquery as input to TOP. Subquery should return scalar. Like so:
SELECT TOP(SELECT COUNT(*) FROM Table2) Col1, Col2 FROM Table1 ORDER BY Col1
Which seems kinda strange for people with MSSQL 2000 experience. In addition it is possible to use TOP with INSERT, UPDATE and DELETE like:
DELETE TOP(1000) FROM Table1 WHERE Id < 10000
Just wanted to share these small tips :)
Sunday, August 05, 2007 10:53 PM