Monday, October 27, 2014

Can SELECT TOP have argument?


This works. But I still don?t realize what was wrong with my syntax. Do those () will convert what?s inside parameter to string so parser could read it correctly? What actually is going on here?



It's just the way it is. Originally there was only SELECT TOP n, where the value after TOP had to be a constant. Then they added the ability to have expression, but then they added the parens. This is so that you can say things like:


SELECT TOP (SELECT ... FROM ...) ... FROM


if you feel like.


The old syntax is deprecated but remains for compatibility reasons.





Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

No comments:

Post a Comment