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 |
mikebird
Aged Yak Warrior
529 Posts |
Posted - 2008-10-23 : 10:44:54
|
How do I set the TOP x part of a query to be one of the parameters in a stored procedure?I want ta simple one, with a startDate, endDate and then to set the number of grouped items? I guessed thatcreate procedure top_classifications (@StartDate datetime, @EndDate datetime, @numbercount int) asSELECT distinct top @numbercount, count(id) popularityFROM <table>WHERE etc etcwould give problems and it did. How do I do it?? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-23 : 10:49:56
|
you cant use parameter for TOP until sql 2005. use ROWCOUNT instead |
 |
|
mikebird
Aged Yak Warrior
529 Posts |
Posted - 2008-10-23 : 10:53:59
|
Very useful!! I am in & out of projects using 2k & 2005 in about the same amount. Is there a list of what's do and not-doable? |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-23 : 10:54:19
|
it will be likecreate procedure top_classifications (@StartDate datetime, @EndDate datetime, @numbercount int) asSET ROWCOUNT @numbercount SELECT distinct count(id) popularityFROM <table>WHERE etc etc |
 |
|
|
|
|