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 |
|
Ferox
Starting Member
18 Posts |
Posted - 2005-05-30 : 07:11:21
|
| Is it possible to write out to a Stored Procedure in this format, where I am passing in a parameter of 10 or 20 etc so I can pull out the top 10 or 20:Create Stored Procedure spsh_Test(@nText INT)Select TOP @nText myFieldFROMmyTableGO |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2005-05-30 : 07:18:00
|
| TOP doesn't accept a variable yet, it will in SQL 2005.Until then, we can use rowcount.SET ROWCOUNT @nTextSELECT myField FROM myTableSET ROWCOUNT 0DamianIta erat quando hic adveni. |
 |
|
|
Ferox
Starting Member
18 Posts |
Posted - 2005-05-30 : 07:28:30
|
| Thanks Merkin, thats exactly what I was looking for! :) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-30 : 08:03:34
|
quote: TOP doesn't accept a variable yet, it will in SQL 2005
I think top can accept variable if we use Dynamic SQLCreate Procedure Returntop (@topno integer)asCreate table #t(i integer identity,n char(10))insert into #t(n) values('test1')insert into #t(n) values('test2')insert into #t(n) values('test3')insert into #t(n) values('test4')insert into #t(n) values('test5')insert into #t(n) values('test6')insert into #t(n) values('test7')insert into #t(n) values('test8')insert into #t(n) values('test9')insert into #t(n) values('test10')Exec('select top '+@topno +' * from #t')RunReturnTop 5 -- will return top 5ReturnTop 7 -- will return top 7MadhivananFailing to plan is Planning to fail |
 |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2005-05-30 : 08:09:00
|
quote: I think top can accept variable if we use Dynamic SQL
Yes, but1. That isn't top accepting a variable param, it's executing a string2. It's silly, we've already solved that problem.DamianIta erat quando hic adveni. |
 |
|
|
|
|
|