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 2005 Forums
 Transact-SQL (2005)
 SELECT TOP x - with a dynamic number

Author  Topic 

GoodTogether
Starting Member

5 Posts

Posted - 2007-11-07 : 11:56:27
Hi,

How would I go about having a "SELECT TOP" stored procedure which returns a dynamic number of results based on a parameter to the stored procedure?

Here is what I tried but the syntax is incorrect.


CREATE PROCEDURE [dbo].[uspSelect_Something]
@ItemCount int
AS
SELECT
TOP @ItemCount
[COLUMN1],
[COLUMN2]
FROM
[Table]
ORDER BY
[COLUMN2] ASC


Thanks

anonymous1
Posting Yak Master

185 Posts

Posted - 2007-11-07 : 12:02:35
TOP @ItemCount
should be
TOP (@ItemCount)
Go to Top of Page

GoodTogether
Starting Member

5 Posts

Posted - 2007-11-07 : 12:07:57
That's done the trick - thanks
Go to Top of Page
   

- Advertisement -