declare @acmastid varchar(40) DECLARE h1 CURSOR FOR SELECT acmastid from loanviewall where type =3 OPEN h1 FETCH NEXT FROM h1 INTO @acmastid WHILE @@FETCH_STATUS = 0 BEGIN delete from acmast where acmastid = @acmastid delete from acExtra where acmastid = @acmastid delete from acmastK where acmastid = @acmastid delete from acMem where acmastid = @acmastid delete from logmast where facttableid = @acmastid delete from acNote where acmastid = @acmastid delete from logdet where facttableid = @acmastid delete from nominee where acmastid = @acmastid delete from dispTrack where acmastid = @acmastid delete from acIntDet where acmastid = @acmastid delete from loan where acmastid = @acmastid delete from drawCCLMast where acmastid = @acmastid delete from drawCCLDet where acmastid = @acmastid delete from lnInsuMast where acmastid = @acmastid delete from pledgeGold where acmastid = @acmastid delete from pledgeVL where acmastid = @acmastid delete from pledgeLand where acmastid = @acmastid delete from pledgeSalary where acmastid = @acmastid delete from pledgeCrop where acmastid = @acmastid delete from intTran where acmastid = @acmastid delete from pledgeDP where acmastid = @acmastid delete from surity where acmastid = @acmastid delete from limitCCLMast where acmastid = @acmastid delete from pledgeOthr where acmastid = @acmastid delete from dispMast where acmastid = @acmastid delete from limitCCLDet where acmastid = @acmastid delete from pledgePL where acmastid = @acmastid delete from pledgePlDet where acmastid = @acmastid delete from rPayMast where acmastid = @acmastid delete from rPayDet where acmastid = @acmastid delete from pledgeLN where acmastid = @acmastid FETCH NEXT FROM h1 INTO @acmastid END DEALLOCATE H1