Can anyone tell me what's wrong with this query? I think I'm in an endless loop?? If you know of a better way to write this, please say so. I need to find and update records accordingly. I'm using SQL Server 7.0.The table names are Taxpayer and Banks and the criteria is stated in the where clauses listed below.If you need ad'l info to help me, please let me know.declare @bnkapp as char(1)declare @rtn as char (10)declare @blnRtn as char (1)declare @PRIMSSN as char (9)declare @ProcStat as char (2)declare @DirState as char (2)declare @AccptCode as char (1)declare @Dan as char (10)declare @ID intdeclare @MaxID intdeclare @Proc as char (2) select @proc = '35', @ID = 0, @maxid = max(taxpayerid) from taxpayer --print @maxid while @ID < @maxid begin select @id = min(taxpayerid) from taxpayer where procstat = @proc select @Primssn = Primssn, @procstat = procstat, @accptcode = accptcode, @Dan = dan, @dirstate = dirstate, @rtn = rtn from taxpayer where taxpayerid = @id and @procstat = @proc if @accptcode = 'A' and (left(@dan,1) = 'R' or left(@dan,1) = 'Q') and @dirstate = 'FD' --and @rtn is not null --begin --print @primssn + " | " + @rtn + " | " + @blnrtn + " | " +@accptcode + " | " + @dan + " | " + @procstat + " | " + @dirstate + " | " --end if exists (select rtn from banks where rtn = @rtn ) begin while @procstat = @proc begin set @blnRtn = 'Y' print @primssn + " | " + @rtn + " | " + @blnrtn + " | " +@accptcode + " | " + @dan + " | " + @procstat + " | " + @dirstate + " | " update taxpayer set procstat = 'TB' where taxpayerid = @id and @blnrtn = 'Y' and @accptcode = 'A' and (@DAN = 'Q' or @DAN = 'R') and @procstat = '35' and @dirstate = 'FD' end end end
(I know how to do this with a cursor, but I'm trying very hard not to use them!
)Thanks!TeresaEdited by - TJ on 08/21/2002 13:33:14