title: How can I get updated column names from different tables and insert their data with column name in a single history table in SQL Server?
body: <p>I have a history table like below</p>
  
  <pre><code>CREATE TABLE [dbo].[t_PettyCash_History] 
  (
      [TableName] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [ColumnName] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [PreviousValue] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [CurrentValue] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [UpdatedBy] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
      [UpdateDate] [varchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
  )
  </code></pre>
  
  <p>What I am trying to do is to write a trigger or stored_procedure which will do the below  </p>
  
  <ol>
  <li>Select the name of the table which is updated  </li>
  <li>Select the name of the column in which data is inserted, updated or deleted  </li>
  <li><p>then insert the values in above table similar like </p>
  
  <pre><code>TableName  ColumnName  PreviousValue   CurrentValue  UpdatedBy   UpdateDate
  t_Table1        Col1        XXX             YYY        A       '20-Mar-2012'
  </code></pre></li>
  </ol>
  
  <p>Thanks in advance !</p>