title: generate x digit random number in sql server 2008 R2
body: <p>I have to generate 12 digit number(bigint) in sql server 2008 R2 itsleft. i have used these methods which i found on the internet</p>
  
  <pre><code>convert(numeric(12,0),rand() * 999999999999) 
  </code></pre>
  
  <p>and</p>
  
  <pre><code>RIGHT(CAST(CAST(NEWID() AS VARBINARY(36)) AS BIGINT), 12)
  </code></pre>
  
  <p>while these do work the problem is sometimes the generated number has leading zeroes and that is stripped resulting in a 10 or 11 digit number.</p>
  
  <p>Is there a consistent way to generate x digit numbers in sql?</p>
  
  <p>Thanks. this is very urgent.</p>