title: How To Turn off Stored Procedure Output
body: <p>SQL Server 2008 R2. Running a stored procedure via a cursor-controlled loop from the SS Management Studio. (below). After 3,000 of 9,000 loops I receive an out of memory error. I believe this is related only to SS Mgmt Studio. So how do I shut off the output of both the calling routine (below) and the invoked SPROC? I am open to another approach to invoke the SPROC (EXECUTE POPULATE_EMA @sym_in, 20,50,100,12,26, @mink_in, @maxk_in;)</p>
  
  <pre><code>DELETE FROM TA_HISTORY
  
  DECLARE tables_cursor CURSOR
     FOR
     SELECT symbol, MinDSeqKey, MaxDSeqKey
     FROM STOCK_VITALS;
  
  OPEN tables_cursor;
  
  DECLARE @sym_in NVARCHAR(10);
  DECLARE @mink_in bigint;
  DECLARE @maxk_in bigint;
  
  FETCH NEXT FROM tables_cursor INTO @sym_in, @mink_in, @maxk_in;
  
  WHILE (@@FETCH_STATUS &lt;&gt; -1)
  BEGIN;
      --PRINT 'Now Processing. ' + @sym_in;
     EXECUTE POPULATE_EMA @sym_in, 20,50,100,12,26, @mink_in, @maxk_in;
  
     INSERT INTO TA_HISTORY(SYMBOL, DSEQKEY, EMA20, EMA50, EMA100, EMA12, EMA26)
     SELECT @sym_in, DSEQKEY, EMA1, EMA2,EMA3,EMA4,EMA5
     FROM temp_ema_data
     WHERE @maxk_in - @mink_in &gt; 49
  
     FETCH NEXT FROM tables_cursor INTO @sym_in, @mink_in, @maxk_in;
  END;
  
  CLOSE tables_cursor;
  
  DEALLOCATE tables_cursor;
  </code></pre>
  
  <p>** EDIT 5/18 - HERE IS THE SPROC - I NEED THE SPROC TO OPERATE ON 9,000+ ROWS IN ANOTHER TABLE.</p>
  
  <pre><code>BEGIN
  
  DROP TABLE temp_ema_data
  
  CREATE TABLE [dbo].[temp_ema_data](
      [n] [int] IDENTITY(1,1) NOT NULL,
      [dseqkey] [bigint] NULL,
      [close_price] [decimal](6, 2) NULL,
      [ema1] [decimal](8, 4) NULL,
      [ema2] [decimal](8, 4) NULL,
      [ema3] [decimal](8, 4) NULL,
      [ema4] [decimal](8, 4) NULL,
      [ema5] [decimal](8, 4) NULL
  ) ON [PRIMARY]
  
  insert into temp_ema_data (dseqkey, close_price)
  select dseqkey,prclose
  from STOCK_HIST
  where Symbol = @Symbol and dseqkey &gt; @MinKey 
  order by dseqkey asc
  
  --declare variables needed
  declare @K1 decimal(4,4), @K2 decimal(4,4), @K3 decimal(4,4), @K4 decimal(4,4)
  , @K5 decimal(4,4)
  declare @prev_ema_1 decimal(8,4), @prev_ema_2 decimal(8,4), @prev_ema_3 decimal(8,4)
  , @prev_ema_4 decimal(8,4), @prev_ema_5 decimal(8,4),@initial_sma_1 decimal(8,4)
  , @initial_sma_2 decimal(8,4), @initial_sma_3 decimal(8,2), @initial_sma_4 decimal(8,4)
  , @initial_sma_5 decimal(8,4)
  declare @anchor int
  
      set @K1 = 2/(1 + @ema_1_intervals + .000)
      set @K2 = 2/(1 + @ema_2_intervals + .000)
      set @K3 = 2/(1 + @ema_3_intervals + .000)
      set @K4 = 2/(1 + @ema_4_intervals + .000)
      set @K5 = 2/(1 + @ema_5_intervals + .000)           
  
  select  @initial_sma_1 = avg(case when n &lt; @ema_1_intervals 
          then close_price else null end),    
          @initial_sma_2  = avg(case when n &lt; @ema_2_intervals 
          then close_price else null end),
          @initial_sma_3  = avg(case when n &lt; @ema_3_intervals 
          then close_price else null end),
          @initial_sma_4  = avg(case when n &lt; @ema_4_intervals 
          then close_price else null end),
          @initial_sma_5  = avg(case when n &lt; @ema_5_intervals 
          then close_price else null end)                     
  from temp_ema_data
  where n &lt; @ema_1_intervals or n &lt; @ema_2_intervals or 
        n &lt; @ema_3_intervals or n &lt; @ema_4_intervals or
        n &lt; @ema_5_intervals
  
  update t1 
      set @prev_ema_1 = case 
      when n &lt; @ema_1_intervals then null         
      when n = @ema_1_intervals then t1.close_price * @K1 + @initial_sma_1 * (1-@K1)  
      when n &gt; @ema_1_intervals then t1.close_price * @K1 + @prev_ema_1 * (1-@K1) 
      end,
      @prev_ema_2 = case when n &lt; @ema_2_intervals then null          
      when n = @ema_2_intervals then t1.close_price * @K2 + @initial_sma_2 * (1-@K2)  
      when n &gt; @ema_2_intervals then t1.close_price * @K2 + @prev_ema_2 * (1-@K2)         
      end, 
      @prev_ema_3 = case when n &lt; @ema_3_intervals then null          
      when n = @ema_3_intervals then t1.close_price * @K3 + @initial_sma_3 * (1-@K3)  
      when n &gt; @ema_3_intervals then t1.close_price * @K3 + @prev_ema_3 * (1-@K3)         
      end, 
      @prev_ema_4 = case when n &lt; @ema_4_intervals then null          
      when n = @ema_4_intervals then t1.close_price * @K4 + @initial_sma_4 * (1-@K4)  
      when n &gt; @ema_4_intervals then t1.close_price * @K4 + @prev_ema_4 * (1-@K4)         
      end, 
      @prev_ema_5 = case when n &lt; @ema_5_intervals then null          
      when n = @ema_5_intervals then t1.close_price * @K5 + @initial_sma_5 * (1-@K5)  
      when n &gt; @ema_5_intervals then t1.close_price * @K5 + @prev_ema_5 * (1-@K5)         
      end,            
      ema1 = @prev_ema_1, ema2 = @prev_ema_2, ema3 = @prev_ema_3, ema4 = @prev_ema_4,
      ema5 = @prev_ema_5, @anchor = n --anchor so that carryover works properly   
  from temp_ema_data t1 with (TABLOCKX) OPTION (MAXDOP 1)
  
  END
  </code></pre>