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
 SQL Server Development (2000)
 Paramaeter part of query syntax...

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 that

create procedure top_classifications (@StartDate datetime, @EndDate datetime, @numbercount int) as
SELECT distinct top @numbercount, count(id) popularity
FROM <table>
WHERE etc etc

would 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
Go to Top of Page

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?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-23 : 10:54:19
it will be like

create procedure top_classifications (@StartDate datetime, @EndDate datetime, @numbercount int) as
SET ROWCOUNT @numbercount

SELECT distinct count(id) popularity
FROM <table>
WHERE etc etc
Go to Top of Page
   

- Advertisement -