title: Get audit history records of any entity record as per CRM view
body: <p>I want to display all audit history data as per MS CRM format.</p>
  
  <p><a href="https://i.stack.imgur.com/ukXPA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ukXPA.png" alt="enter image description here"></a></p>
  
  <p>I have imported all records from AuditBase table from CRM to another Database server table.</p>
  
  <p>I want this table records using SQL query in Dynamics CRM format (as per above image).</p>
  
  <p>I have done so far</p>
  
  <pre><code>select 
  AB.CreatedOn as [Created On],SUB.FullName [Changed By],
  Value as Event,ab.AttributeMask [Changed Field],
  AB.changeData [Old Value],'' [New Value] from Auditbase AB
  
  inner join StringMap SM on SM.AttributeValue=AB.Action and SM.AttributeName='action'
  inner join SystemUserBase SUB on SUB.SystemUserId=AB.UserId
  
  --inner join MetadataSchema.Attribute ar on ab.AttributeMask = ar.ColumnNumber
  --INNER JOIN MetadataSchema.Entity en ON ar.EntityId = en.EntityId and en.ObjectTypeCode=AB.ObjectTypeCode
  
  --inner join Contact C on C.ContactId=AB.ObjectId
  where objectid='00000000-0000-0000-000-000000000000' 
  Order by AB.CreatedOn desc
  </code></pre>
  
  <p>My problem is AttributeMask is a comma separated value that i need to compare with MetadataSchema.Attribute table's columnnumber field. And how to get New value from that entity.</p>
  
  <p>I have already checked this link : <a href="https://social.microsoft.com/Forums/en-US/708fe8d6-67d5-481d-aaad-1ac62c2ff755/sql-query-to-get-data-from-audit-history-for-opportunity-entity?forum=crmdevelopment" rel="noreferrer">Sql query to get data from audit history for opportunity entity</a>, but its not giving me the [New Value].</p>
  
  <p><strong>NOTE</strong> : I can not use "RetrieveRecordChangeHistoryResponse", because i need to show these data in external webpage from sql table(Not CRM database).</p>