--select * from op_wms where CUSTOMERNAME='วเตบบใฬ์' declare @customername varchar(50) set @customername='วเตบบใฬ์' delete from op_wms where CUSTOMERNAME=@customername delete from OP_WMS_IN_PLAN where CUSTOMERNAME=@customername delete from OP_WMS_OUT_PLAN where CUSTOMERNAME=@customername delete from OP_WMS_IN_DO where CUSTOMERNAME=@customername delete from OP_WMS_OUT_DO where CUSTOMERNAME=@customername delete from OP_WMS_CHANGE where wmsid not in(select wmsid from op_wms) delete from OP_WMS_PHYSICS where wmsid not in(select wmsid from op_wms) delete from OP_WMS_PHYSICS_CHANGE where wmsid not in(select wmsid from op_wms) delete from OP_WMS_LOGIC where wmsid not in(select wmsid from op_wms) delete from OP_WMS_FEERATE_DETAIL where FEERATEID not in(select wmsid from op_wms) and FEERATEID not in(select FEERATEID from OP_WMS_FEERATE) delete from ch_fee where bsno not in (select bsno from v_op_bs) delete from OP_WMS_IN_PLAN_GOODS where WMSPLANID not in(select WMSPLANID from OP_WMS_IN_PLAN) delete from OP_WMS_IN_DO_GOODS where WMSDOID not in(select WMSDOID from OP_WMS_IN_DO) delete from OP_WMS_OUT_PLAN_DETAIL where WMSPLANID not in(select WMSPLANID from OP_WMS_OUT_PLAN) delete from OP_WMS_OUT_DO_GOODS where WMSDOID not in(select WMSDOID from OP_WMS_OUT_DO)