title: SQL Server sequence set current value
body: <p>I am using SQL Server 2012 (v11.0.2100) and I want to create a sequence that starts with a random (dynamic) number but I wasn't able to do this, also I put my effort to find a good solution for this but I haven't found something that will satisfy me. </p>
  
  <p>The case that I tried and failed: </p>
  
  <pre><code> DECLARE @sth bigint
  
   SET @sth = 1000
  
   ALTER SEQUENCE StreamEntrySequence
   RESTART WITH @sth;
  </code></pre>
  
  <p>Error : </p>
  
  <blockquote>
    <p>Incorrect syntax near '@sth'</p>
  </blockquote>
  
  <p>An ugly solution    </p>
  
  <pre><code> declare @sth bigint;
   declare @i bigint;
  
   SET @sth = 100000    ; 
  
   while @i&lt;@sth;
   BEGIN
      SET @i= next value for StreamEntrySequence;
   END
  </code></pre>
  
  <p>Is there other way to set the current value or the start value to a random value? Maybe using server procedures? </p>