Selecting top 'x' number of rows through a sp

  • 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?

  • Its fine, Got it:

    SELECT TOP (@TOP)

    cheers

  • Gavin

    you need to use parentheses i.e.

    ...

    select top (@top)

    ...

    Kev

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply