IF EXISTS (SELECT 1 FROM SYS.TABLES WHERE NAME='LD0P0SERVICECATEGORYCUSTSHIP_UPDATE_SAVE')
BEGIN
DROP TABLE LD0P0SERVICECATEGORYCUSTSHIP_UPDATE_SAVE
END
;

SELECT * INTO LD0P0SERVICECATEGORYCUSTSHIP_UPDATE_SAVE FROM LD0P0SERVICECATEGORYCUSTSHIP S WHERE ARCHSTATE IN (5,7) AND ID IN (SELECT SERVCATCUSTID FROM LD0P0CASE WHERE ARCHSTATE IN (3,4))
;

UPDATE S SET ARCHSTATE=3 FROM LD0P0SERVICECATEGORYCUSTSHIP S WHERE ARCHSTATE IN (5,7) AND ID IN (SELECT SERVCATCUSTID FROM LD0P0CASE WHERE ARCHSTATE IN (3,4))
;

