Results 1 to 13 of 13

Thread: [RESOLVED] Optimize very slow UPDATE

Threaded View

  1. #1

    Thread Starter
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Resolved [RESOLVED] Optimize very slow UPDATE

    I have this Update at work and I need to optimize it.

    It's terribly slow because it's done in a subquery at field level with complicated conditions.
    Does anybody know any way to rewrite this to make run faster?
    Code:
    UPDATE #POS SET SaldoDespuesEvento = (
    		  SELECT  SUM(Importe) 
    			FROM  #POS CTACTE2
    		   WHERE  CTACTE2.CodComitente = #POS.CodComitente  
    		     AND  CTACTE2.CodMoneda = #POS.CodMoneda
    		     AND  CTACTE2.EstaAnulado = 0 
    		     AND  (  
    					DATEDIFF(day, CTACTE2.FechaLiquidacion, #POS.FechaLiquidacion) > 0 
    					OR   (
    							DATEDIFF(day, CTACTE2.FechaLiquidacion, #POS.FechaLiquidacion) = 0 
    				 			AND  (	
    				 					#POS.CodCtaCorrienteMon >= CTACTE2.CodCtaCorrienteMon
    				 				  )
    				 		 )
    				   )
    		  ) 
    WHERE #POS.EstaAnulado = 0
      AND #POS.EsSaldoAnterior = 0
    Last edited by jcis; Nov 7th, 2013 at 01:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width