title: How can I use Cross Apply to multiple rows?
body: <p>I have this table  : </p>
  
  <pre><code>;WITH cte AS (
      SELECT Name='john' , Times=1    
      UNION ALL
      SELECT 'paul' ,2
      UNION ALL
      SELECT 'george' , 3
      UNION ALL
      SELECT 'ringo' , 1
  )
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/RZ0KZ.png" alt="enter image description here"></p>
  
  <p>I want to display each row , <code>Times</code> times : </p>
  
  <pre><code>John 1
  Paul 2
  Paul 2
  george 3
  george 3
  george 3
  ringo 1
  </code></pre>
  
  <p>So I know that if I write <code>Cross apply</code> like : </p>
  
  <pre><code>SELECT *
  FROM   cte
         CROSS APPLY(
          SELECT 1 AS ca
          UNION 
          SELECT 2
         ) y
  </code></pre>
  
  <p>Then each row will be displayed 2 times.</p>
  
  <p><img src="https://i.stack.imgur.com/9KjnL.png" alt="enter image description here"></p>
  
  <p>but I don't want 2 times. I want <code>Times</code> times</p>
  
  <p><strong>Question</strong></p>
  
  <p>How can I enhance my query to do it ?</p>
  
  <p>nb : </p>
  
  <p>a non-intelligent solution that came to my mind is to create a udf which create <code>Times</code> rows for <code>n</code> parameter - and then in the <code>Cross Apply</code> I simply do : select * from <code>udf_toTable(Times)</code>)</p>