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/生成疗程替换原项目支付明细.sql

502 lines
8.1 KiB

1 year ago
declare @index int
select @index = 1;
goto BeginTask
RunTask:
print db_name()
---------------------------------------------
DECLARE @BillId BIGINT
DECLARE Cur CURSOR FOR SELECT FBillId
FROM TMemberSaleExchange
WHERE FChangeMode = 3
OPEN Cur
FETCH Cur INTO @BillId
WHILE @@FETCH_STATUS=0
BEGIN
IF NOT EXISTS(SELECT 1 FROM TMemberSaleDetailPayment WHERE FBillId = @BillId)
BEGIN
--<EFBFBD><EFBFBD><EFBFBD>²<EFBFBD><EFBFBD><EFBFBD>
UPDATE B
SET B.FDeptId = A.FDeptId
FROM TMemberSaleExchangeSource AS B,TItem AS A,TCourse AS C
WHERE A.FId = C.FItemId
AND B.FCourseId = C.FId
AND B.FBillID = @BillID
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ
INSERT TMemberSaleDetailPayment(FId,FBillId,FBizType,FDetailId,FPayTypeId,FPayAmt)
SELECT dbo.FNNewId(),@BillId,'Exchange' + '.Source',A.FId,B.FPayTypeId,B.FPayAmt * (CASE WHEN C.FAmount = 0 THEN 1 ELSE A.FPurAmount / C.FAmount END) AS FPayAmt
FROM TMemberSaleExchangeSource AS A,
TMemberSalePayment AS B,
(SELECT A.FBillId, SUM(A.FPurAmount) AS FAmount
FROM TMemberSaleExchangeSource AS A GROUP BY A.FBillId) AS C
WHERE A.FBillId = B.FBillId
AND A.FBillId = @BillId
AND A.FBillId = C.FBillId
END
FETCH Cur INTO @BillId
END
CLOSE Cur
DEALLOCATE Cur
-- SELECT * FROM TMemberSaleDetailPayment WHERE FBizType = 'Exchange.Source'
-- DELETE TMemberSaleDetailPayment WHERE FBizType = 'Exchange.Source'
---------------------------------------------
SELECT @index = @index + 1
BeginTask:
IF @Index = 1
BEGIN
use BaoTou_MeiJueShi
goto RunTask
END
ELSE IF @Index = 2
BEGIN
use ChangSha_Demo1
goto RunTask
END
ELSE IF @Index = 3
BEGIN
use DongYing_ANan
goto RunTask
END
ELSE IF @Index = 4
BEGIN
use DongYing_DongHua
goto RunTask
END
ELSE IF @Index = 5
BEGIN
use DongYing_JiangRenWuQu
goto RunTask
END
ELSE IF @Index = 6
BEGIN
use DongYing_JiangRenYuHua
goto RunTask
END
ELSE IF @Index = 7
BEGIN
use DongYing_LiRenDao
goto RunTask
END
ELSE IF @Index = 8
BEGIN
use DongYing_MuLanJie
goto RunTask
END
ELSE IF @Index = 9
BEGIN
use DongYing_PLBB
goto RunTask
END
ELSE IF @Index = 10
BEGIN
use HuHeHaoTe_FeiWen
goto RunTask
END
ELSE IF @Index = 11
BEGIN
use HuHeHaoTe_HeQi
goto RunTask
END
ELSE IF @Index = 12
BEGIN
use HuHeHaoTe_YunXin
goto RunTask
END
ELSE IF @Index = 13
BEGIN
use JiNan_ABiao
goto RunTask
END
ELSE IF @Index = 14
BEGIN
use JiNan_ATao
goto RunTask
END
ELSE IF @Index = 15
BEGIN
use JiNan_Great
goto RunTask
END
ELSE IF @Index = 16
BEGIN
use JiNan_JinZhi
goto RunTask
END
ELSE IF @Index = 17
BEGIN
use JiNan_MeiShang
goto RunTask
END
ELSE IF @Index = 18
BEGIN
use JiNan_MingGe
goto RunTask
END
ELSE IF @Index = 19
BEGIN
use JiNan_ShangPin
goto RunTask
END
ELSE IF @Index = 20
BEGIN
use JiNan_XiuMuMing
goto RunTask
END
ELSE IF @Index = 21
BEGIN
use JinCheng_NiHaoPiaoLiang
goto RunTask
END
ELSE IF @Index = 22
BEGIN
use LaiYang_HuaYun
goto RunTask
END
ELSE IF @Index = 23
BEGIN
use LaiZhou_MangGuo
goto RunTask
END
ELSE IF @Index = 24
BEGIN
use LiaoCheng_ShiJiJinDian
goto RunTask
END
ELSE IF @Index = 25
BEGIN
use LinYi_DaXiangGang
goto RunTask
END
ELSE IF @Index = 26
BEGIN
use LinYi_DiFanNi
goto RunTask
END
ELSE IF @Index = 27
BEGIN
use QingDao_AC
goto RunTask
END
ELSE IF @Index = 28
BEGIN
use QingDao_DaDaShiDa
goto RunTask
END
ELSE IF @Index = 29
BEGIN
use QingDao_DaLiangZao
goto RunTask
END
ELSE IF @Index = 30
BEGIN
use QingDao_FengHuangMingLiu
goto RunTask
END
ELSE IF @Index = 31
BEGIN
use QingDao_HeChen
goto RunTask
END
ELSE IF @Index = 32
BEGIN
use QingDao_HongRenGuan
goto RunTask
END
ELSE IF @Index = 33
BEGIN
use QingDao_KeLin
goto RunTask
END
ELSE IF @Index = 34
BEGIN
use QingDao_LaFeiPaiRui
goto RunTask
END
ELSE IF @Index = 35
BEGIN
use QingDao_MaLin
goto RunTask
END
ELSE IF @Index = 36
BEGIN
use QingDao_ManXiu
goto RunTask
END
ELSE IF @Index = 37
BEGIN
use QingDao_ME
goto RunTask
END
ELSE IF @Index = 38
BEGIN
use QingDao_MeiGe
goto RunTask
END
ELSE IF @Index = 39
BEGIN
use QingDao_MingYu
goto RunTask
END
ELSE IF @Index = 40
BEGIN
use QingDao_NiSiKa
goto RunTask
END
ELSE IF @Index = 41
BEGIN
use QingDao_NiSiKa_DRF
goto RunTask
END
ELSE IF @Index = 42
BEGIN
use QingDao_NiSiKa_JiaoZhou
goto RunTask
END
ELSE IF @Index = 43
BEGIN
use QingDao_PuXin
goto RunTask
END
ELSE IF @Index = 44
BEGIN
use QingDao_QiShang
goto RunTask
END
ELSE IF @Index = 45
BEGIN
use QingDao_ShangDiLi
goto RunTask
END
ELSE IF @Index = 46
BEGIN
use QingDao_ShaXuan
goto RunTask
END
ELSE IF @Index = 47
BEGIN
use QingDao_SiNuoMei
goto RunTask
END
ELSE IF @Index = 48
BEGIN
use QingDao_Sweet
goto RunTask
END
ELSE IF @Index = 49
BEGIN
use QingDao_XiaoJun
goto RunTask
END
ELSE IF @Index = 50
BEGIN
use QingDao_YanSe
goto RunTask
END
ELSE IF @Index = 51
BEGIN
use QingDao_ZiRanFaZe
goto RunTask
END
ELSE IF @Index = 52
BEGIN
use SaiDao_Demo
goto RunTask
END
ELSE IF @Index = 53
BEGIN
use SaiDao_Demo_MF
goto RunTask
END
ELSE IF @Index = 54
BEGIN
use SaiDao_Demo_MR
goto RunTask
END
ELSE IF @Index = 55
BEGIN
use SaiDao_Dev
goto RunTask
END
ELSE IF @Index = 56
BEGIN
use SaiDao_HuBei
goto RunTask
END
ELSE IF @Index = 57
BEGIN
use SaiDao_Jike
goto RunTask
END
ELSE IF @Index = 58
BEGIN
use SaiDao_NingXia
goto RunTask
END
ELSE IF @Index = 59
BEGIN
use SaiDao_ShanXi
goto RunTask
END
ELSE IF @Index = 60
BEGIN
use SaiDao_ShanXiDemo
goto RunTask
END
ELSE IF @Index = 61
BEGIN
use SaiDaoDemo
goto RunTask
END
ELSE IF @Index = 62
BEGIN
use ShanTou_Demo1
goto RunTask
END
ELSE IF @Index = 63
BEGIN
use ShouGuang_JinGongZi
goto RunTask
END
ELSE IF @Index = 64
BEGIN
use TaiYuan_BaYa
goto RunTask
END
ELSE IF @Index = 65
BEGIN
use TaiYuan_ChengYi_01
goto RunTask
END
ELSE IF @Index = 66
BEGIN
use TaiYuan_ChengYi_02
goto RunTask
END
ELSE IF @Index = 67
BEGIN
use TaiYuan_FaXianTa
goto RunTask
END
ELSE IF @Index = 68
BEGIN
use TaiYuan_FengGe
goto RunTask
END
ELSE IF @Index = 69
BEGIN
use TaiYuan_HeTangYueSe
goto RunTask
END
ELSE IF @Index = 70
BEGIN
use TaiYuan_JinRiShuoFa
goto RunTask
END
ELSE IF @Index = 71
BEGIN
use TaiYuan_ShaXuan_02
goto RunTask
END
ELSE IF @Index = 72
BEGIN
use TaiYuan_TouFaChangLe
goto RunTask
END
ELSE IF @Index = 73
BEGIN
use TaiYuan_XiMenXuan
goto RunTask
END
ELSE IF @Index = 74
BEGIN
use TaiYuan_XinGanJue
goto RunTask
END
ELSE IF @Index = 75
BEGIN
use TaiYuan_ZhouJi
goto RunTask
END
ELSE IF @Index = 76
BEGIN
use WeiFang_RuiLi
goto RunTask
END
ELSE IF @Index = 77
BEGIN
use WeiFang_XiMei
goto RunTask
END
ELSE IF @Index = 78
BEGIN
use XiaoYi_OSA
goto RunTask
END
ELSE IF @Index = 79
BEGIN
use XiNing_MingZhi
goto RunTask
END
ELSE IF @Index = 80
BEGIN
use XinYang_WanHongXiuShou
goto RunTask
END
ELSE IF @Index = 81
BEGIN
use XinZhou_BaiTianE
goto RunTask
END
ELSE IF @Index = 82
BEGIN
use YangQuan_ManDu
goto RunTask
END
ELSE IF @Index = 83
BEGIN
use YanTai_RunSiFang
goto RunTask
END
ELSE IF @Index = 84
BEGIN
use YinChuan_TX
goto RunTask
END
ELSE IF @Index = 85
BEGIN
use YunCheng_ShouXuan
goto RunTask
END
ELSE IF @Index = 86
BEGIN
use ZhengZhou_HaiRunManHaDun
goto RunTask
END
ELSE IF @Index = 87
BEGIN
use ZhengZhou_HaiRunWenGeHua
goto RunTask
END
ELSE IF @Index = 88
BEGIN
use ZhengZhou_KaKa
goto RunTask
END
ELSE IF @Index = 89
BEGIN
use ZhengZhou_LiShuangShuang
goto RunTask
END
ELSE IF @Index = 90
BEGIN
use ZiBo_YanYi
goto RunTask
END
PRINT 'END'