title: SQL TRIGGER handling multiple INSERTED rows
body: <p>I have an <code>UPDATE</code> which looks like this:</p>
  
  <pre><code>UPDATE STOR SET
      STOR.BLOC1 = T.BLOC1,
      STOR.BLOC2 = T.BLOC2,
      STOR.BLOC3 = T.BLOC3
  FROM BLDG B INNER JOIN STOR S
  ON S.B_ID = B.B_ID
  CROSS APPLY dbo.INVENTORIZE(B.B_ID) AS T;
  </code></pre>
  
  <p>And a <code>TRIGGER</code> which is meant to insert a row (like a log) for each update above.</p>
  
  <pre><code>CREATE TRIGGER trgrCYCLE
  ON STOR
  FOR UPDATE
  AS
  DECLARE @BLDG int, @ACT varchar(4), @QTY decimal(3,1);
  
  SET @BLDG = (SELECT B_ID FROM inserted)
  SET @QTY= (SELECT BLOC1 FROM inserted)
  SET @ACT = CASE WHEN @QTY &lt; 0 THEN 'SELL'
              ELSE 'BUY' END
  
  INSERT INTO INVT VALUES (CURRENT_TIMESTAMP, @BLDG, @ACT, @QTY)
  </code></pre>
  
  <p>I have two problems for which I need assistance:</p>
  
  <ol>
  <li><p>the fact of the <code>inserted</code> pseudo table having multiple rows is returning an error ("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."). I haven't been able to transport answers in similar questions to my case.</p></li>
  <li><p>how to have the trigger work for <strong><em>n</em></strong> number of BLOC columns (BLOC1, BLOC2, BLOC3, BLOCn...)</p></li>
  </ol>