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)
 Selecting top 'x' number of rows through a sp

Author  Topic 

Gavin1977
Starting Member

16 Posts

Posted - 2008-06-24 : 05:40:02
Hello all.

Im trying to write a stored procedure which i can stipulate the top number of rows it returns. I know i use the following syntax:

SELECT TOP 5 


And i know i need to pass the number of rows i want as a variable to the stored proceudre like:


@Top as Integer 


But when i try and do the following. SQL Server complains about the syntax:

SELECT TOP @Top 


Can anyone advise me how i should be doing this?



harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-06-24 : 05:41:23
[code]SELECT TOP (@Top)...[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Gavin1977
Starting Member

16 Posts

Posted - 2008-06-24 : 05:46:30
Ahh excellant, thanks very much.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-24 : 07:01:40
This information is also available in Books Online, the Microsoft SQL Server help file.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -