title: Using EXEC command as INSERT VALUE in SQL
body: <p>I want to be able to do something like this:
  My stored proc will always return a number (tinyint)</p>
  
  <pre><code>INSERT INTO CustomerSelections
             ([draw_date]
             ,[val1]
             ,[val2]
             ,[val3]
             ,[val4]
             ,[val5]
             ,[val6])
       VALUES
             (
             '2013-07-05'
             ,EXEC GenerateRandomNumbers 1, 49, 1, 0
             ,EXEC GenerateRandomNumbers 1, 49, 1, 0
             ,EXEC GenerateRandomNumbers 1, 49, 1, 0
             ,EXEC GenerateRandomNumbers 1, 49, 1, 0
             ,EXEC GenerateRandomNumbers 1, 49, 1, 0
             ,EXEC GenerateRandomNumbers 1, 49, 1, 0
             )
  </code></pre>
  
  <p>But i am not aware of how to get the values in there?</p>
  
  <p><strong>UPDATE:</strong>
  I tried something like this:</p>
  
  <p>I put the passed values into a stored proc called:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[GetUniqueLottoNumber] 
  
  AS
  BEGIN
  
  DECLARE @return_value int
  
  EXEC    @return_value = [dbo].[GenerateRandomNumbers]
          @StartNumber = 1,
          @EndNumber = 49,
          @QuantityToOutput = 1,
          @AllowDuplicates = 0
  
  END
  </code></pre>
  
  <p>Then did this:</p>
  
  <pre><code>CREATE TABLE #tmp (Number TINYINT)
  DECLARE @q nvarchar(4000)
  DECLARE @return_value int
  SET @q = 'EXEC  @return_value = [dbo].[GetUniqueLottoNumber]';
  
  INSERT INTO  #tmp (Number)
  EXEC sp_executesql @q
  </code></pre>
  
  <p>But it doesnt like it when i put @q in the insert values.</p>