Help get a best perfomance

  • Hi all, i have this query:

    DECLARE @pid_partida_cliente INT

    DECLARE get_idPartida_cliente CURSOR FOR

    SELECT distinct id_partida_cliente from spotCronogramaPartidaCliente where id_oferta=1895

    OPEN get_idPartida_cliente

    FETCH get_idPartida_cliente INTO @pid_partida_cliente

    WHILE (@@FETCH_STATUS = 0 )

    BEGIN

    update spotPartidaCliente

    set tiempo_partida_cliente=(select sum(avance_dias)

    from spotcronogramapartidacliente CPC where CPC.id_oferta=1895

    and CPC.id_partida_cliente=@pid_partida_cliente)

    WHERE id_partida_cliente=@pid_partida_cliente

    FETCH get_idPartida_cliente INTO @pid_partida_cliente

    END

    CLOSE get_idPartida_cliente

    DEALLOCATE get_idPartida_cliente

    Someone can help me to get a better perfomance rewriting the code please?

    Thanks.

    ____________________________________________________________________________
    Rafo*

  • without knowing the ddl and sample data its difficult to give you an answer but you could try this ( modify further as required).

    update spc

    set tiempo_partida_cliente= d.sums

    from spotPartidaCliente spc

    join (select CPC.id_partida_cliente,sum(avance_dias) as sums

    from spotcronogramapartidacliente CPC where CPC.id_oferta=1895

    group by CPC.id_partida_cliente ) d

    on spc.id_partida_cliente = d.id_partida_cliente

    sheesh 🙂 totally forgot to mention the above code wont use the cursor anymore. My mistake

    Jayanth Kurup[/url]

  • You don't need a cursor for that. That is one thing that is slowing you down.

    The probability of survival is inversely proportional to the angle of arrival.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply