title: SQL SP: Store collection of ids from select query in a TVP
body: <p>All I need is to store the list of userids in a TVP named temp in my SQL SP. A single select query will return all the ids required. But my confusion is how can I store it in the TVP temp. As I am the beginner in SQL SP, I Google-d few questions in SO. But they were using the loop. I am not sure how I can use looping in my case.</p>
  
  <pre><code>CREATE PROCEDURE deleteDetails @mainname nvarchar(max)
  AS
  BEGIN
      declare @mainid int;
      declare #temp table (id int not null)
      select @mainid = id from major where name = @mainname
      select #temp = userid from userTable where mainid = @mainid --Got Stuck here :(
  
      delete from detailsTable where id in (select * from #temp)
  END
  GO
  </code></pre>
  
  <p>Any help/suggestion would be useful to me.</p>