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 |
|
dotnetallday
Starting Member
16 Posts |
Posted - 2004-01-16 : 04:35:57
|
I'd like to perform a SELECT TOP n * FROM Table1 where "n" is equal to a parameter passed. I've got something like this but obviously it doesn't work. I'm somewhat of a newbie to SQL, so please excuse me if the question seems idiotic.CREATE PROC dbo.GetTopAnswers(@Count int)ASSELECT TOP @COUNT * FROM tblAnswersGO Thanks! |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-01-16 : 04:47:12
|
| set rowcount @COUNTselect * from tblAnswersset rowcount 0ordeclare @sql varchar(8000)select @sql = 'select top ' + convert(varchar(20),@COUNT) + ' from tblAnswers'exec (@sql)orwait for about 10 months.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2004-01-16 : 04:47:55
|
| create PROC dbo.GetTopAnswers (@Count int)ASdeclare @sql nvarchar(1000)set @sql='SELECT TOP '+convert(varchar(10),@COUNT)+' * FROM tblanswers'exec sp_executesql @sqlGOHe is a fool for five minutes who asks , but who does not ask remains a fool for life! |
 |
|
|
|
|
|