using variable with the TOP keyword in the SQL procedure

  • Hi,

    This is my code:

    CREATE PROCEDURE test2 (@number int)

     AS

    select top @number field1 from table A

    order by field1

       I can't save the stored procedure. I want to passing one number into this procedure so that it can generate the result for me. The number is dynamic. Please kindly advice.

     

     

    Thanks and Regards

    lss

    lss

  • exec('select top ' + @number + ' field1 from table A

    order by field1')

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

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