title: SQL Stored Procedure Simultaneously Call Issue
body: <p>I have stored procedure in the sql server 2008, my stored procedure calculate and get the last number "not primary key" from column from table B and add one ( +1 ) to this number to use it on the next statement on the same stored procedure. </p>
  
  <p>My issue that i have a duplicate number some times, i think this happened when multiple users call the stored procedure on the same time. is this the issue and how can i solve it </p>
  
  <p>my code is like the below:- </p>
  
  <pre><code>DECLARE @ID AS NVARCHAR(10)
  SET @ID =   (
                  SELECT TOP 1 MyNo
                  FROM Employee
                  WHERE (
                              (TypeID = @TypeID) AND
                              (Year = @Year)
                        )
                  ORDER BY ID DESC
              )
  
  SET @ID = ISNULL(@ID,0) + 1
  
  
  INSERT INTO Employee (name,lname,MyNo) VALUES (@name,@lname,@MyNo)
  </code></pre>