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.
| 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 |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-04-18 : 16:19:47
|
| SET ROWCOUNT @variableCould be an alternative...rockmoose |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-04-18 : 16:32:50
|
| Y ask YIs TOP even ANSI Compliant?Brett8-) |
 |
|
|
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. |
 |
|
|
|
|
|