title: Stored procerudure that calculate number of rows with same number and place that value to other table
body: <p>I need help with an assignment where I'm supposed to create a Stored Procedure in SQL. I'm new to SQL and it's the first course in databases that I take. I'm using SQL Server Managment Studio 2012. </p>
  
  <p>I have 2 tables, table book, and table bookcopy. Table book has three columns, isbn (the primary key), title and nrOfCopies. The bookcopy table also has three columns, barcode (the primary key), status and isbn( a foreign key that references the isbn-column in table book).</p>
  
  <p>So the assignment is to create a stored procedure for a specific isbn-value (the number of rows with the same isbn-number) that updates the nrOfCopies-column in the book-table. The number of rows for a specific isbn-number will be the value in the nrOfCopies-column for that isbn-number in the book-table.</p>
  
  <p>I tried to do it like this:</p>
  
  <pre><code>CREATE PROCEDURE spNrOfBooks
  AS
  BEGIN
      DECLARE @calcNr AS INT
      SET @calcNR = (SELECT COUNT(isbn) FROM bookcopy)
      UPDATE book SET nrOfCopies = @calcNr WHERE isbn LIKE (SELECT isbn FROM bookcopy)
  END
  </code></pre>
  
  <p>When I execute this procedure I get an error message (Msg 512).</p>
  
  <p>Can someone please help me by pointing out what I can do to solve this? </p>