title: SQL RAND() function used to return a repeatable sample set result, but results changed?
body: <pre><code>SELECT ITEMID FROM IMPORT_DOCUMENTS 
  WHERE ITEMID IN(SELECT ITEM_ID FROM PUBLIC_FOLDER_DOCUMENTS WHERE FOLDER_ID = 96) 
  AND (ABS(CAST((BINARY_CHECKSUM(*) * RAND(734014465)) as int))% 369279) &lt; 506 
  </code></pre>
  
  <p>Typically, we use <code>ORDER BY NEWID()</code> in SQL Server 2008 to obtain random samples, but in this case the client has requested we use a <code>RAND([seed])</code> function to obtain a sample that we can again replicate later.</p>
  
  <p>The query above is what we used to generate one sample group.  We wanted to obtain about 500 rows from a group of 369,279 records.  (this explains the 369279 &amp; 506 values)</p>
  
  <p>We ran this early today and received 501 records, which is what we're looking for. We repeated these same results many times. Now, running this later we're receiving a different set of 527 records. My understanding is that this query's results would be static, but apparently not.  Can anyone explain how these results could have changed, given the query we have used?  </p>
  
  <p>Please note that the population defined by <code>FOLDER_ID = 96</code> has not changed in any way.</p>
  
  <p>Thank you!</p>