sql - Query taking too much -


i trying execute updates while condition returns results, problem when testing query never finishes. here query;

while(select count(*) agreement agr agr.id in (   select toa.id agreement_temporaryonceagreement toa toa.executed =1) , agr.endingdate null) > 0 begin declare @agreementid int; set @agreementid =  ( select top 1 agr.id agreement agr agr.id in (   select toa.id agreement_temporaryonceagreement toa toa.executed =1) , agr.endingdate null ) update agreement set endingdate = (   select tado.date temporaryagreementsdateofexecution tado     tado.agreementid = cast(@agreementid int)) agreement.id = cast(@agreementid int); end; 

you don't need loop. single update query resembling should job done.

update set endingdate = tado.date agreement join temporaryagreementsdateofexecution tado on a.agreementid = tado.agreementid  join agreement_temporaryonceagreement toa on a.id = toa.id  endingdate null , toa.executed = 1 

there might slight variations depending on rdbms using.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -