Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SELECT TOP n restrictions

Author  Topic 

emirs
Starting Member

1 Post

Posted - 2005-04-18 : 14:51:01
Does anyone know why SELECT TOP n ... statement can't accept a parameter.
I am aweare of workaround with EXEC or sp_executesql...
So, what I really need is answer WHY a parameter can't be used in a statement.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-04-18 : 15:07:07
I'm not sure what good this will do for you, but the simple answer is because that is the way Microsoft setup SQL Server.





CODO ERGO SUM
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-04-18 : 16:19:47
SET ROWCOUNT @variable
Could be an alternative...

rockmoose
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-04-18 : 16:32:50
Y ask Y

Is TOP even ANSI Compliant?



Brett

8-)
Go to Top of Page

Billpl
Yak Posting Veteran

71 Posts

Posted - 2005-04-18 : 20:39:09
Because it makes no relational sense. When you say "top" what do mean? Top floors of a building, Top of your class? Top "Smith"s because their first name starts with "A" rather than "F"? In relational sense a certain "chunk" of data is not supposed be singled out simply because it is on top of the others unless there is some form of predetermined logic, say top 10 batting averages, top 10% of test scores. Thus a predetermined value is acceptable and an ambiguous one is not. If you could pass any number then well, you could start "rigging" things to make sense out of nonsense and that would make you a bad bad boy for not following the rules.
Go to Top of Page
   

- Advertisement -