title: How to insert top selecting number as a parameter in a stored procedure
body: <p>I'm trying to get top 10, top 5 records of a table time to time. So I'm gonna create a stored procedure with a parameter which is accepting the number of records as the parameter. But it gives me an error near @number in the query. </p>
  
  <p>This is what i tried, this gives me a syntax error:</p>
  
  <blockquote>
    <p>error=Msg 102, Level 15, State 1, Procedure selectVoterTopGivenNumberRECS, Line 10 Incorrect syntax near '@number'.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>CREATE PROCEDURE selectVoterTopGivenNumberRECS
    (
      @number int
    )
  AS 
  BEGIN
  BEGIN TRANSACTION 
  SET NOCOUNT ON;
  --Query
  
   SELECT TOP @number 
  
  V.NICorPP as NICorPP,V.fName+' '+V.mName+' '+V.lName AS Name,
  V.DOB AS DateofBirth,
  CASE (V.gender) 
  
    WHEN 1 THEN 'Male'
    WHEN 2 THEN 'Female' 
    END  AS Gender,V.vtaddress AS VoterAddress,V.phHome AS ContactHome,
     V.phMob AS  ContactMobile,V.occupation AS Occupation, 
    V.occRegID AS RegisteredOCCID,LGD.LGDivName
  FROM Voter V
  INNER JOIN LGDivision LGD ON V.lgDiv=LGD.LGDivID
     WHERE V.vtStatus='Active'; 
  
  COMMIT TRANSACTION
  END;
  </code></pre>
  
  <p>How to overcome this?</p>