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/ImportBK/导BOKA_1_在BOKA数据库执行_套餐.sql

229 lines
7.6 KiB

1 year ago
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FId' AND id = object_id('gtc01'))
ALTER TABLE gtc01 ADD
FId VARCHAR(20) NOT NULL DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT))
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FNo' AND id = object_id('gtc01'))
ALTER TABLE gtc01 ADD
FNo VARCHAR(30)
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FId' AND id = object_id('gtc02'))
ALTER TABLE gtc02 ADD
FId VARCHAR(20) NOT NULL DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)),
FItemId VARCHAR(20) NOT NULL DEFAULT 0 ,
FPackId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FId' AND id = object_id('gtc03'))
ALTER TABLE gtc03 ADD
FId VARCHAR(20) NOT NULL DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)),
FGoodsId VARCHAR(20) NOT NULL DEFAULT 0 ,
FPackId VARCHAR(20) NOT NULL DEFAULT 0,
FUnitId VARCHAR(20) NOT NULL DEFAULT 0
--
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FCardId' AND id = object_id('gtc04'))
ALTER TABLE gtc04 ADD
FCardId VARCHAR(20) NOT NULL DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)),
FItemId VARCHAR(20) NOT NULL DEFAULT 0 ,
FPackId VARCHAR(20) NOT NULL DEFAULT 0,
FMemId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FPurTimes' AND id = object_id('gtc04'))
ALTER TABLE gtc04 ADD
FPurTimes DECIMAL(18,6) NOT NULL DEFAULT 0,
FUsedPurTimes DECIMAL(18,6) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FAdjustPrice' AND id = object_id('gtc04'))
ALTER TABLE gtc04 ADD
FAdjustPrice DECIMAL(18,6) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FMemPackId' AND id = object_id('gtc04'))
ALTER TABLE gtc04 ADD
FMemPackId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FMemPackId' AND id = object_id('gtc08'))
ALTER TABLE gtc08 ADD
FMemPackId VARCHAR(20) NOT NULL DEFAULT 0
--<EFBFBD><EFBFBD>Ա<EFBFBD>ײͲ<EFBFBD>Ʒ
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FCardId' AND id = object_id('gtc08'))
ALTER TABLE gtc08 ADD
FId VARCHAR(20) NOT NULL DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)),
FGoodsId VARCHAR(20) NOT NULL DEFAULT 0 ,
FPackId VARCHAR(20) NOT NULL DEFAULT 0,
FMemId VARCHAR(20) NOT NULL DEFAULT 0,
FQuantity DECIMAL(18,6) NOT NULL DEFAULT 0,
FUsedQuantity DECIMAL(18,6) NOT NULL DEFAULT 0,
FUnitId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FAdjustPrice' AND id = object_id('gtc08'))
ALTER TABLE gtc08 ADD FAdjustPrice DECIMAL(18,6) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FPurTimes' AND id = object_id('gtc04'))
ALTER TABLE gtc04 ADD
FPurTimes DECIMAL(18,6) NOT NULL DEFAULT 0,
FUsedPurTimes DECIMAL(18,6) NOT NULL DEFAULT 0
UPDATE gtc01
SET FNo = gta01c
--<EFBFBD><EFBFBD><EFBFBD>¸<EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>ID
update a
set a.FId = b.FId
FROM gtc01 AS A, (select FNo,FId from gtc01 where gta00c = '001') AS B
WHERE a.gta00c NOT IN('','001')
AND a.FNo = B.FNo
--<EFBFBD>ײ<EFBFBD><EFBFBD><EFBFBD>Ŀ
UPDATE A
SET A.FItemId = B.FId
FROM gtc02 AS A,gdm01 AS B
WHERE A.gtb02c = B.gda01c
AND A.gtb00c = B.gda00c
AND B.gda00c = '001'
UPDATE A
SET A.FPackId = B.FId
FROM gtc02 AS A,gtc01 AS B
WHERE A.gtb01c = B.gta01c
AND A.gtb00c = B.gta00c
--<EFBFBD>ײͲ<EFBFBD>Ʒ
UPDATE A
SET A.FGoodsId = B.FId,
A.FUnitId = (SELECT FId FROM gsm02 WHERE gsb00c = '001' AND gsb02c = gfa07c AND gsb01c = 'K')
FROM gtc03 AS A,gfm01 AS B
WHERE A.gtd02c = B.gfa01c
AND A.gtd00c = B.gfa00c
AND B.gfa00c = '001'
UPDATE A
SET A.FPackId = B.FId
FROM gtc03 AS A,gtc01 AS B
WHERE A.gtd01c = B.gta01c
AND A.gtd00c = B.gta00c
--<EFBFBD><EFBFBD>Ա<EFBFBD>ײ<EFBFBD>
UPDATE A
SET A.FMemId = B.FMemId
FROM gtc04 AS A,gcm01 AS B
WHERE A.gte01c = gca01c
AND A.gte00c = gca00c
AND gca00c = gca13d
UPDATE A
SET A.FPackId = B.FPackId,
A.FItemId = B.FItemId,
A.FAdjustPrice = B.gtb04f,
A.FPurTimes = CASE WHEN gte06f > gte04f THEN gte06f ELSE gte04f END,
A.FUsedPurTimes = CASE WHEN gte06f > gte04f THEN 0 ELSE gte04f - gte06f END
FROM gtc04 AS A,gtc02 AS B
WHERE A.gte02c = gtb01c
AND A.gte03c = gtb02c
AND b.gtb00c = '001'
UPDATE A
SET A.FItemId = B.FId
FROM gtc04 AS A,gdm01 AS B
WHERE A.gte03c = gda01c
AND b.gda00c = '001'
UPDATE A
SET A.FPackId = B.FId
FROM gtc04 AS A,gtc01 AS B
WHERE A.gte02c = gta01c
AND b.gta00c = '001'
--<EFBFBD><EFBFBD>Ա<EFBFBD>ײͲ<EFBFBD>Ʒ
UPDATE A
SET A.FMemId = B.FMemId
FROM gtc08 AS A,gcm01 AS B
WHERE A.gtj01c = gca01c
AND A.gtj00c = gca00c
AND gca00c = gca13d
UPDATE A
SET A.FPackId = B.FId
FROM gtc08 AS A,gtc01 AS B
WHERE A.gtj02c = gta01c
AND b.gta00c = '001'
UPDATE A
SET A.FPackId = B.FPackId,
A.FGoodsId = B.FGoodsId,
A.FAdjustPrice = isnull(B.gtd04f,0),
A.FQuantity = CASE WHEN gtj06f > gtj04f THEN gtj06f ELSE gtj04f END,
A.FUsedQuantity = CASE WHEN gtj06f > gtj04f THEN 0 ELSE gtj04f - gtj06f END
FROM gtc08 AS A,gtc03 AS B
WHERE A.gtj02c = gtd01c
AND A.gtj03c = gtd02c
AND b.gtd00c = '001'
UPDATE A
SET A.FGoodsId = B.FId
FROM gtc08 AS A,gfm01 as b
WHERE A.gtj03c = gfa01c
AND b.gfa00c = '001'
--DROP TABLE TMemberCoursePack
SELECT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)) AS FMemPackId,A.FMemId,FPackId AS FPackId,gte00c AS FCompNo
INTO TMemberCoursePack
FROM gtc04 as a,gcm01
WHERE gte00c = gca00c
AND gte01c = gca01c
AND gca00c = gca13d
GROUP BY a.FMemId,FPackId,gte00c
UNION ALL
SELECT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)) AS FMemPackId,a.FMemId,FPackId AS FPackId,gtj00c AS FCompNo
FROM gtc08 as a,gcm01
WHERE gtj00c = gca00c
AND gtj01c = gca01c
AND gtj00c = gca13d
GROUP BY a.FMemId,FPackId,gtj00c
UPDATE A
SET A.FMemPackId = B.FMemPackId
FROM gtc04 AS A,TMemberCoursePack AS B
WHERE A.FMemId = B.FMemId
AND A.FPackId = B.FPackId
AND a.gte00c = B.FCompNo
UPDATE A
SET A.FMemPackId = B.FMemPackId
FROM gtc08 AS A,TMemberCoursePack AS B
WHERE A.FMemId = B.FMemId
AND A.FPackId = B.FPackId
AND a.gtj00c = B.FCompNo
ALTER TABLE TMemberCoursePack ADD FCompId BIGINT
SELECT * FROM TMemberCoursePack WHERE FPackId = '0'
SELECT * FROM gtc04 WHERE FPackId = '0'
SELECT * FROM gtc08 WHERE FPackId = '0'
SELECT * FROM gtc04,gcm01
WHERE gca00c = gte00c
AND gca00c = gca13d
AND gca01c = gte01c
AND gte02c NOT IN(SELECT gta01c FROM gtc01)
SELECT * FROM gtc08 WHERE gtj02c NOT IN(SELECT gta01c FROM gtc01)
select db_name()
UPDATE gsm01 SET gsa02c = ',M$+!' WHERE gsa01c = 'sp025'