title: How to convert cycle to table-based query?
body: <p>I have a table <code>IDTable</code> with one column <code>ID</code> and also I have one table valued function <code>MyProcedure</code> that takes a parameter. This parameter is my column <code>ID</code>. This function returns a table. I need to call this function for every value in column <code>ID</code>. I have such code:</p>
  
  <pre><code>Declare @ResultTable table(
    ClientID nvarchar(50) null,
    [Date] datetime null,
    Item varchar(100) null
  )
  
  Declare @IDTable table(
      id int
   )
  
   declare @counter as int 
   set @counter = isnull( (select max(id) from @IDTable),0) 
   while @counter&lt;&gt;0 
   begin 
      set @ID = (select id from @IDTable where id=@counter)
  
      insert into @ResultTable
         select ClientID
                [Date],
                Item
         from MyProcedure (@ID)
  
      delete from @IBTable where id=@counter 
      set @counter=isnull((select max(id) from @IBTable),0) 
   end
  </code></pre>
  
  <p>I need to remove while cycle and make set-based alternative. How can I do it?</p>