title: Manipulating the list of data from stored procedure to be used in another stored procedure
body: <p>Currently I'm writing a stored procedureusing T-SQL in SQL Server. My script contains code to run another stored procedure to get list of data from a table. I want to manipulate the data, using the list of data to modify them for another purpose (e.g. summing up a column and adding more lists of data) from the stored procedure. A way that I know is to create a temporary table. But after that, I'm not so sure. Please help. thanks. </p>
  
  <p>This is my code:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[AJU_Rpt_ARAgingSp]
      (@Slsman_Starting slsmantype = NULL,
       @Slsman_Ending slsmantype = NULL,
       @Custnum_Starting custnumtype = NULL,
       @Custnum_Ending custnumtype = NULL,
       @CustType endusertypetype = NULL,
       @CutOff_Date datetype = NULL,
       @SumToCorp ListYesNoType = NULL, -- &gt;&gt; 0 = individual, 1 = corp customer
       @ShowActive ListYesNoType = NULL, -- &gt;&gt; 0 = all trx, 1 = active only
       @TransDomCurr ListYesNoType = NULL, -- &gt;&gt; 0 = dont convert, 1 = convert to local currency
       @AgingBasis ArAgeByType = NULL, --&gt;&gt; i = invoice date, d = due date
       @LeftToRight ListYesNoType = NULL, -- &gt;&gt; 0 = right to left, 1 = left to right
       @CurrSite NVARCHAR(8),
       @ShowDetailInfo NVARCHAR(1) = NULL)
  AS
  BEGIN
      SET NOCOUNT ON
  
      IF ISNULL(@CurrSite ,'') = '' 
         SET @CurrSite = (SELECT TOP 1 site_ref FROM parms_mst)
  
      DECLARE @v_StartDate DateType
  
      SET @Slsman_Starting = ISNULL(@Slsman_Starting, dbo.LowCharacter())
      SET @Slsman_Ending = ISNULL(@Slsman_Ending, dbo.HighCharacter())
      SET @Custnum_Starting = ISNULL(@Custnum_Starting, dbo.LowCharacter())
      SET @Custnum_Ending = ISNULL(@Custnum_Ending, dbo.HighCharacter())
      SET @v_StartDate = dbo.LowDate()
      SET @CutOff_Date = GETDATE()
  
      EXEC dbo.ApplyDateOffsetSp @v_StartDate OUT, NULL, 0
  
      EXEC AJU_Rpt_DebtorSp
           @CustNumStart          = @Custnum_Starting
          ,@CustNumEnd            = @Custnum_Ending
          ,@DistDateStart         = @v_StartDate
          ,@DistDateEnd           = @CutOff_Date
          ,@CurrCodeStart         = NULL
          ,@CurrCodeEnd           = NULL
          ,@SlsmanStart           = @Slsman_Starting
          ,@SlsmanEnd             = @Slsman_Ending
          ,@TerritoryStart        = NULL
          ,@TerritoryEnd          = NULL
          ,@CustTypeStart         = NULL
          ,@CustTypeEnd           = NULL
          ,@SiteGroup             = @CurrSite
          ,@ConsolidatePayment    = NULL
          ,@DisplayResult         = 1
  
  END
  </code></pre>