UPDATE A SET A.FDeptId = B.FDeptId FROM TConsumeItem AS A,TItem AS B WHERE A.FItemId = B.FId UPDATE A SET A.FDeptId = B.FDeptId FROM TConsumeGoods AS A, TGoods AS B WHERE A.FGoodsId = B.FId UPDATE A SET A.FDeptId = B.FDeptId FROM TMemberSaleCard AS A, TMemberCardType AS B WHERE A.FCardTypeId = B.FId UPDATE A SET A.FDeptId = B.FDeptId FROM TMemberSaleCourse AS A, TItem AS B WHERE A.FItemId = B.FId UPDATE A SET A.FDeptId = B.FDeptId FROM TMemberSaleCoursePack AS A, TCoursePack AS B WHERE A.FPackId = B.FId UPDATE A SET A.FDeptId = B.FDeptId FROM TMemberArrear AS A, TConsumeItem AS B WHERE A.FTransId = B.FBillId AND A.FTransDetailId = B.FId AND A.FBillType = 'XF' UPDATE A SET A.FDeptId = B.FDeptId FROM TMemberArrear AS A, TMemberSaleCard AS B WHERE A.FTransId = B.FBillId AND A.FBillType = 'KK' AND A.FBizType IN( 'CardSale','CardRchg') UPDATE A SET A.FDeptId = B.FDeptId FROM TMemberArrear AS A, TMemberSaleCourse AS B WHERE A.FTransId = B.FBillId AND A.FTransDetailId = B.FId AND A.FBillType = 'KK' AND A.FBizType IN( 'CourseSale') UPDATE A SET A.FDeptId = B.FDeptId FROM TMemberArrear AS A, TMemberSaleCoursePack AS B WHERE A.FTransId = B.FBillId AND A.FTransDetailId = B.FId AND A.FBillType = 'KK' AND A.FBizType IN( 'CoursePackSale') UPDATE A SET A.FDeptId = B.FDeptId FROM TMemberSaleRepay AS A, TMemberArrear AS B WHERE A.FArrearId = B.FId SELECT * FROM TConsumeItem WHERE FDeptId NOT IN(SELECT FId FROM TBasicType) OR FDeptId = 0 SELECT * FROM TConsumeGoods WHERE FDeptId NOT IN(SELECT FId FROM TBasicType)OR FDeptId = 0 SELECT * FROM TMemberSaleCourse WHERE FDeptId NOT IN(SELECT FId FROM TBasicType)OR FDeptId = 0 SELECT * FROM TMemberSaleCard WHERE FDeptId NOT IN(SELECT FId FROM TBasicType)OR FDeptId = 0 SELECT * FROM TMemberSaleCoursePack WHERE FDeptId NOT IN(SELECT FId FROM TBasicType)OR FDeptId = 0 SELECT * FROM TConsumeItem WHERE SELECT * FROM TEmployee WHERE FDeptId NOT IN (SELECT FId FROM TBasicType) SELECT * FROM TItem WHERE FDeptId NOT IN (SELECT FId FROM TBasicType) SELECT * FROM TGoods WHERE FDeptId NOT IN (SELECT FId FROM TBasicType) --更新项目基本资料上的部门 UPDATE B SET B.FDeptId = A.FDeptId FROM TConsumeItem AS B,TItem AS A WHERE A.FId = B.FItemId --把项目基本资料没有设置部门 UPDATE I SET I.FDeptId = B.FDeptId FROM TConsumeItem AS I , TConsumeItemEmployee AS A, TEmployee AS B WITH(NOLOCK), ( SELECT A.FBillId,A.FDetailId,MIN(A.FWorkType) AS FWorkType FROM TConsumeItemEmployee AS A WITH(NOLOCK) GROUP BY A.FBillId,A.FDetailId ) AS C WHERE A.FEmpId = B.FId AND A.FBillId = C.FBillId AND A.FDetailID = C.FDetailId AND A.FWorkType = C.FWorkType AND I.FDeptId = 0 AND I.FId = A.FDetailId --更新产品基本资料上的部门 UPDATE B SET B.FDeptId = A.FDeptId FROM TConsumeGoods AS B,TGoods AS A WHERE A.FId = B.FGoodsId --把产品基本资料没有设置部门 UPDATE I SET I.FDeptId = B.FDeptId FROM TConsumeGoods AS I , TConsumeGoodsEmployee AS A, TEmployee AS B WITH(NOLOCK), ( SELECT A.FBillId,A.FDetailId,MIN(A.FWorkType) AS FWorkType FROM TConsumeGoodsEmployee AS A WITH(NOLOCK) GROUP BY A.FBillId,A.FDetailId ) AS C WHERE A.FEmpId = B.FId AND A.FBillId = C.FBillId AND A.FDetailID = C.FDetailId AND A.FWorkType = C.FWorkType AND I.FDeptId = 0 AND I.FId = A.FDetailId --疗程 UPDATE B SET B.FDeptId = A.FDeptId FROM TMemberSaleCourse AS B,TItem AS A WHERE A.FId = B.FItemId --卡 UPDATE B SET B.FDeptId = A.FDeptId FROM TMemberSaleCard AS B,TMemberCardType AS A WHERE A.FId = B.FCardTypeId