title: Generate random id (fixed length) in T-SQL
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13957380/generating-random-string-in-t-sql">Generating random string in T-SQL</a>  </p>
  </blockquote>
  
  
  
  <p>I need to convert this C# method in T-SQL:</p>
  
  <pre><code> public static string GenerateRandomID(int size)
      {
          StringBuilder pass = new StringBuilder();
          Random random = new Random();
          for (int i = 0; i &lt; size; i++)
          {
              int binary = random.Next(0, 2);
              switch (binary)
              {
                  case 0:
                      char ch = (Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))));
                      pass.Append(ch);
                      break;
                  case 1:
                      int num = random.Next(1, 10);
                      pass.Append(num);
                      break;
              }
          }
          return pass.ToString();
      }
  </code></pre>
  
  <p>Usage example: string output = GenerateRandomID(15)</p>
  
  <p>output should look like: O1REGVIDK7T4R9R</p>
  
  <p>Someone have an idea...</p>