How to stop job from moving to next step if no records match per FETCH routine below.
-----------------------------------------------------------
USE Process
GO
declare @lot varchar (25),@sap varchar(10), @process varchar(10)
DECLARE field_cursor CURSOR FOR
SELECT product_order, sap_no, process_order FROM TEOSLot where product_order <> ''
OPEN field_cursor
-- Perform the first fetch.
FETCH NEXT FROM field_cursor INTO @lot,@sap,@process
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
update teosautodata
set sap_no=@sap, process_order=@process WHERE product_order=@lot
--copy updated recordsets to TEOSMaster table on Server, then delete same recordsets from TeosAutoData.
IF EXISTS(SELECT * FROM Teosautodata WHERE product_order=@lot and process_order=@process and sap_no=@sap)
insert into teosmaster (Logtime,systemmode,TE_601,TE_351,PIT_350,TE_504,TE_502,TE_358,TE_352,TE_353,LIT_450,LIT_350,LIT_451,LIT_452,LIT_453,TE_362,TE_355,TE_356,sap_no,product_order,process_order)
SELECT Logtime,systemmode,TE_601,TE_351,PIT_350,TE_504,TE_502,TE_358,TE_352,TE_353,LIT_450,LIT_350,LIT_451,LIT_452,LIT_453,TE_362,TE_355,TE_356,sap_no,product_order,process_order FROM Teosautodata where sap_no=@sap and process_order=@process and product_order=@lot
--copy updated recordsets to TEOSMastertemp table on Server, then delete same recordsets from TeosAutoData.
IF EXISTS(SELECT * FROM Teosautodata WHERE product_order=@lot and process_order=@process and sap_no=@sap)
insert into teosmastertemp (Logtime,systemmode,TE_601,TE_351,PIT_350,TE_504,TE_502,TE_358,TE_352,TE_353,LIT_450,LIT_350,LIT_451,LIT_452,LIT_453,TE_362,TE_355,TE_356,sap_no,product_order,process_order)
SELECT Logtime,systemmode,TE_601,TE_351,PIT_350,TE_504,TE_502,TE_358,TE_352,TE_353,LIT_450,LIT_350,LIT_451,LIT_452,LIT_453,TE_362,TE_355,TE_356,sap_no,product_order,process_order FROM Teosautodata where sap_no=@sap and process_order=@process and product_order=@lot
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM field_cursor
INTO @lot,@sap,@process
END
CLOSE field_cursor
DEALLOCATE field_cursor
GO