Bulk update of the same row column using trigger in SQL Server
<p>I have this table structure:</p>

<pre><code>CREATE TABLE JoiningDate 
(
    Id INT,
    DateofJoining DATETIME,
    STATUS VARCHAR(10),
    DaysCount INT
)
</code></pre>

<p>This table is filled with 1000 records with DaysCount as NULL value.</p>

<p>I have created a trigger as below for this table to update <code>DaysCount</code>. Whenever there is an update of <code>DateOfJoining</code> or <code>Status</code> columns, <code>DaysCount</code> should get calculated in the trigger and updated automatically. </p>

<p>This is the outline of the trigger:</p>

<pre><code>CREATE TRIGGER [dbo].[trigger_JoiningDate] 
ON [dbo].[JoiningDate]
AFTER INSERT, UPDATE
AS
BEGIN
    DECLARE @Id INT
    DECLARE @DateJoining DATETIME
    DECLARE @Result INT

    SELECT @Id = Id,
           @DateJoining = DateofJoining, 
    FROM INSERTED   

    SET @Result = [Formula To Calculate Days]

    UPDATE JoiningDate 
    SET DaysCount = @Result  
    WHERE Id = @Id
END
</code></pre>

<p>I'm able to see the count getting updated for single record. But for bulk updates it is updating only the first record.</p>

<p>With the help of stackoverflow, I have tried using instead of trigger, TRIGGER_NESTLEVEL(), etc options but still all other rest of the rows not getting updated.</p>

<p>Quicker help appreciated.</p>