You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
sql-tools/更新单据部门.txt

145 lines
3.8 KiB

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)
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵIJ<EFBFBD><EFBFBD><EFBFBD>
UPDATE B
SET B.FDeptId = A.FDeptId
FROM TConsumeItem AS B,TItem AS A
WHERE A.FId = B.FItemId
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>
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
--<EFBFBD><EFBFBD><EFBFBD>²<EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵIJ<EFBFBD><EFBFBD><EFBFBD>
UPDATE B
SET B.FDeptId = A.FDeptId
FROM TConsumeGoods AS B,TGoods AS A
WHERE A.FId = B.FGoodsId
--<EFBFBD>Ѳ<EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>
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
--<EFBFBD>Ƴ<EFBFBD>
UPDATE B
SET B.FDeptId = A.FDeptId
FROM TMemberSaleCourse AS B,TItem AS A
WHERE A.FId = B.FItemId
--<EFBFBD><EFBFBD>
UPDATE B
SET B.FDeptId = A.FDeptId
FROM TMemberSaleCard AS B,TMemberCardType AS A
WHERE A.FId = B.FCardTypeId