title: Convert x digit random number to varchar in SQL Server
body: <p>I am creating a 14 digit random number in SQL Server 2008 R2 using the following query:</p>
  
  <pre><code>select FLOOR(RAND() * POWER(CAST(10 as BIGINT), 14))
  </code></pre>
  
  <p>Now I need to convert this number into varchar for which I use this query:</p>
  
  <pre><code>select 
      convert(varchar(50), FLOOR(RAND() * POWER(CAST(10 as BIGINT), 14)))
  </code></pre>
  
  <p>It convert the number but in <code>6.74151e+013</code> form.</p>
  
  <p>So I tried this:</p>
  
  <pre><code>select 
      convert(varchar(50), FLOOR(RAND() * POWER(CAST(10 as BIGINT), 5))) +
      convert(varchar(50), FLOOR(RAND() * POWER(CAST(10 as BIGINT), 5))) + 
      convert(varchar(50), FLOOR(RAND() * POWER(CAST(10 as BIGINT), 4)))
  </code></pre>
  
  <p>It does create a 14 digit varchar but I feel there can be a shorter way to do so. I have tried various other ways too but they return the answer in the <code>6.74151e+013</code> format which I cannot use.</p>
  
  <p>Please help.</p>
  
  <p>EDIT: If there is another way of creating a 14 digit random numeric string directly(i.e. without using rand()) then do tell that also.</p>