title: Generate a hash for a set of rows in sql server
body: <p>Is there any way in SQL Server 2012 to generate a hash of a set of rows and columns?</p>
  
  <p>I want to generate a hash, store it on the parent record.  The when an update comes in, I'll compare the incoming hash with the parent record hash and I'll know whether the data has changed.</p>
  
  <p>So something like this would be nice:</p>
  
  <pre><code>SELECT GENERATEHASH(CONCATENATE(Name, Description, AnotherColumn))
  FROM MyChildTable WHERE ParentId = 2 -- subset of data belong to parent record 2
  </code></pre>
  
  <p>"CONCATENATE" would be an aggregate function which would not only concat the columns, but also, the rows inside the resultset.  Like MAX, but returning everything as a string concatenation.</p>
  
  <p>Hopefully this helps you see what I mean anyway! </p>
  
  <p>The fundamental problem I'm trying to solve is that my client's system perform imports of vast amounts of hierarchical data.  If I can avoid processing through the use of hashes, then I would think this will save a lot of time. At the moment, the SP is running 300% slower when having to process duplicate data. </p>
  
  <p>Many thanks</p>