title: Subquery returned more than 1 value. This is not permitted
body: <pre><code>ALTER TRIGGER t1
  ON dbo.Customers
  
  FOR INSERT
  AS
  
  BEGIN TRANSACTION
  
  /* variables */
  
  DECLARE
      @maxid bigint
  
  SELECT @customerid = id FROM inserted
  
  SET IDENTITY_INSERT dbo.new_table ON
  
  DECLARE
      @maxid bigint
  
  SELECT @maxid = MAX(ID) FROM new_table
  
  INSERT INTO new_table (ID, ParentID, Foo, Bar, Buzz)
      SELECT ID+@maxid, ParentID+@maxid, Foo, Bar, Buzz FROM initial_table
  
  SET IDENTITY_INSERT dbo.new_tableOFF
  
  /* execute */
  COMMIT TRANSACTION
  
  GO
  </code></pre>
  
  <p>fails with:</p>
  
  <blockquote>
    <p>SQL Server Subquery returned more than 1 value. This is not permitted
    when the subquery follows =, !=, &lt;, &lt;= , >, >= or when the subquery is
    used as an expression</p>
  </blockquote>
  
  <p>How to fix it?</p>
  
  <p>What I am trying to do is</p>
  
  <ul>
  <li>insert <code>id</code> and <code>parentid</code>, each INCREASED by <code>@maxid</code></li>
  <li>from <code>initial_table</code> </li>
  <li>into <code>new_table</code></li>
  </ul>
  
  <p>thnx</p>
  
  <p><strong>new_table</strong></p>
  
  <pre><code>id (bigint) 
  parentid (bigint - linked to id) 
  foo | bar | buzz (others are nvarchar, not really important)
  </code></pre>
  
  <p><strong>initial table</strong></p>
  
  <pre><code>id (bigint) 
  parentid (bigint - linked to id)
  foo | bar | buzz (others are nvarchar, not really important)
  </code></pre>