title: SQL Server stored procedure inserting duplicate rows
body: <p>I have a table with column <code>GetDup</code> and I'd like to the duplicate records based on the value of this column. For example, if value on is 1 in <code>GetDup</code>, then duplicate the record once. If value in the column is 2, then duplicate the record twice and so on and the statement has to be in looping statement.   </p>
  
  <p>What will be a good way to write a stored procedures for this? Please help.   </p>
  
  <p>Input:</p>
  
  <pre><code>+--------+--------------+---------------+
  | Getdup | CustomerName | CustomerAdd   |
  +--------+--------------+---------------+
  |      1 | John         | 123 SomeWhere |
  |      2 | Bob          | 987 SomeWhere |
  +--------+--------------+---------------+
  </code></pre>
  
  <p>What I want:</p>
  
  <pre><code>+--------+--------------+---------------+
  | Getdup | CustomerName | CustomerAdd   |
  +--------+--------------+---------------+
  |      1 | John         | 123 SomeWhere |
  |      1 | John         | 123 SomeWhere |
  |      2 | Bob          | 987 SomeWhere |
  |      2 | Bob          | 987 SomeWhere |
  |      2 | Bob          | 987 SomeWhere |
  +--------+--------------+---------------+
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/FbjTR.jpg" rel="nofollow noreferrer">picture of data</a></p>