title: Execute a Stored Procedure with a table as input
body: <p>Is it possible to use a table as input for a stored procedure?</p>
  
  <pre><code>EXEC sp_Proc SELECT * FROM myTable
  </code></pre>
  
  <p>I've created a function to return a table consisting of a single record.</p>
  
  <pre><code>ALTER FUNCTION dbo.preEmail
  (
   @Num INT,
   @WID INT
  )
  RETURNS 
  @Results TABLE 
  
  (
   WID char(10),
   Company nchar(50),
   Tech nchar(25),
   StartDate datetime,
   Description varchar(max),
   Address varchar(200),
   Phone varchar(15),
   Status varchar(35)
  
  )
  AS
  BEGIN
  
  INSERT INTO @Results 
      (WID, Company, Tech, StartDate, Description, Address, Phone, Status)
  
  SELECT WID, company, tech, startDate, description, address, phone, status
  FROM wo_tbl
  WHERE Num = @Number AND wid = @WID
  
  
  RETURN 
  END
  GO
  </code></pre>
  
  <p>Next I have a stored procedure that sends an email to the tech that is scheduled in the above record.</p>
  
  <pre><code>EXEC sp_emailTech @WID, @Company, @Tech, @StartDate, @Description, @Address, @Phone, @Status. 
  </code></pre>
  
  <p>but I'd rather do</p>
  
  <pre><code>EXEC sp_emailTech SELECT * FROM dbo.preEmail(1, 5746)
  </code></pre>