title: How Columns_update() Function Works in Trigger To Find Updated Columns Name
body: <p>I am confused about trigger function <code>Columns_Update()</code>. </p>
  
  <p>I have a basic idea about this function that it returns a <code>varbinary</code> and it is use to get updated columns in trigger</p>
  
  <p>Even I have find the code to get updated columns name but have still confusion in bit representation. I would be very thankful if someone explains this function or gives reference </p>
  
  <p>I got the following function</p>
  
  <pre><code>CREATE FUNCTION dbo.GenColUpdated
  (@Col INT, @ColTotal INT)
  RETURNS INT
  AS
  BEGIN;
  
  
  DECLARE
  @ColByte INT,
  @ColTotalByte INT,
  @ColBit INT;
  -- Calculate Byte Positions
  SET @ColTotalByte = 1 + ((@ColTotal-1) /8);
  SET @ColByte = 1 + ((@Col-1)/8);
  SET @ColBit = @Col - ((@ColByte-1) * 8);
  RETURN Power(2, @ColBit + ((@ColTotalByte-@ColByte) * 8)-1);
  END;
  </code></pre>
  
  <p>and use that function in trigger like this</p>
  
  <pre><code>set @ColUpdatedTemp = dbo.GenColUpdated(@ColCounter, @ColTotal) ;
  
  If COLUMNS_UPDATED() &amp; dbo.GenColUpdated(@ColCounter, @ColTotal) = @ColUpdatedTemp
  </code></pre>
  
  <p>I didn't understand this condition  </p>
  
  <pre><code>dbo.GenColUpdated(@ColCounter,@ColTotal) =
          @ColUpdatedTemp
  </code></pre>
  
  <p>it doesn't make Any sense to me .First you are assign the value and than Check it </p>