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

629 lines
20 KiB

1 year ago
--<EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>иýű<EFBFBD>
--<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>ʼ
/*
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
select ' EXEC PDropColumn ''' + a.name + ''', ''' + b.name +''''
FROM sysobjects as a,syscolumns as b
WHERE a.id = b.id
AND b.name IN('FId','FMemId','FCardId','FItemId','FCourseId','FNo','FMemNo','FCardNo','FFromChild',
'FCardTypeId','FTypeId','FMasterId','FPayTypeId')
DROP TABLE TInventory
*/
use yangquan_meishu_bk
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'haa46i' AND id = object_id('ham01'))
BEGIN
ALTER TABLE ham01 ADD haa46i INT DEFAULT 1
END
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'gak44i' AND id = object_id('gam10'))
BEGIN
ALTER TABLE gam10 ADD gak44i INT DEFAULT 1
END
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FId' AND id = object_id('gam01'))
ALTER TABLE gam01 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 = 'FId' AND id = object_id('gam04'))
ALTER TABLE gam04 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 = 'FId' AND id = object_id('gdm01'))
ALTER TABLE gdm01 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('gdm01'))
ALTER TABLE gdm01 ADD FNo VARCHAR(30) NOT NULL DEFAULT ''
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FFromChild' AND id = object_id('gdm01'))
ALTER TABLE gdm01 ADD FFromChild BIT NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FCourseId' AND id = object_id('gdm01'))
ALTER TABLE gdm01 ADD FCourseId VARCHAR(30) NOT NULL DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT))
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FId' AND id = object_id('gfm01'))
ALTER TABLE gfm01 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('gfm01'))
ALTER TABLE gfm01 ADD FNo VARCHAR(20) NOT NULL DEFAULT ''
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FFromChild' AND id = object_id('gfm01'))
ALTER TABLE gfm01 ADD FFromChild BIT NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FId' AND id = object_id('ham01'))
ALTER TABLE ham01 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 = 'FId' AND id = object_id('gsm02'))
ALTER TABLE gsm02 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 = 'FItemId' AND id = object_id('hem01'))
ALTER TABLE hem01 ADD FItemId BIGINT NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FPayTypeId' AND id = object_id('hem01'))
ALTER TABLE hem01 ADD FPayTypeId BIGINT NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FItemId' AND id = object_id('gdm06'))
ALTER TABLE gdm06 ADD FItemId VARCHAR(20) NOT NULL DEFAULT ''
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FId' AND id = object_id('gdm06'))
ALTER TABLE gdm06 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 = 'FId' AND id = object_id('gdm07'))
ALTER TABLE gdm07 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 = 'FMasterId' AND id = object_id('gdm07'))
ALTER TABLE gdm07 ADD FMasterId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FPayTypeId' AND id = object_id('gdm07'))
ALTER TABLE gdm07 ADD FPayTypeId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FCardTypeId' AND id = object_id('gdm07'))
ALTER TABLE gdm07 ADD FCardTypeId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FId' AND id = object_id('gam10'))
ALTER TABLE gam10 ADD FId VARCHAR(20) NOT NULL DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT))
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FItemId' AND id = object_id('gfm05'))
ALTER TABLE gfm05 ADD FItemId BIGINT
, FGoodsId BIGINT
, FUnitId BIGINT
--<EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD>
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FEmpId' AND id = object_id('hem02'))
ALTER TABLE hem02 ADD FEmpId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FItemId' AND id = object_id('hem02'))
ALTER TABLE hem02 ADD FItemId VARCHAR(20) NOT NULL DEFAULT 0
--<EFBFBD><EFBFBD>Ա
--ALTER TABLE gbm01 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 = 'FMemId' AND id = object_id('gcm01'))
ALTER TABLE gcm01 ADD
FMemId VARCHAR(20) NOT NULL DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)),
FCardId VARCHAR(20) NOT NULL DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)),
FCardTypeId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FMemId' AND id = object_id('gbm01'))
ALTER TABLE gbm01 ADD
FMemId VARCHAR(20) NOT NULL DEFAULT ''
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FMemId' AND id = object_id('gcm03'))
ALTER TABLE gcm03 ADD
FMemId VARCHAR(20) NOT NULL DEFAULT 0,
FCardId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FId' AND id = object_id('gcm06'))
ALTER TABLE gcm06 ADD
FId VARCHAR(20) NOT NULL DEFAULT abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT)),
FMemId VARCHAR(20) NOT NULL DEFAULT 0,
FCardId VARCHAR(20) NOT NULL DEFAULT 0,
FItemId VARCHAR(20) NOT NULL DEFAULT 0,
FCourseId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FMemId' AND id = object_id('gcm04'))
ALTER TABLE gcm04 ADD
FMemId VARCHAR(20) NOT NULL DEFAULT 0,
FCardId VARCHAR(20) NOT NULL DEFAULT 0
IF NOT EXISTS(SELECT TOP 1 1 FROM syscolumns WHERE name = 'FMemId' AND id = object_id('gcm20'))
ALTER TABLE gcm20 ADD
FMemId VARCHAR(20) NOT NULL DEFAULT 0,
FCardId VARCHAR(20) NOT NULL DEFAULT 0
--<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-----------------------------------------------------------------------------------------------------
--<EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>ʼ
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD>Ҫִ<EFBFBD>еڶ<EFBFBD><EFBFBD><EFBFBD>
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳһ<EFBFBD><EFBFBD>Ŀ<EFBFBD>Ͳ<EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF (SELECT COUNT(1) FROM gam05) > 1
BEGIN
----------------------------------------------
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ID,<EFBFBD>Ƴ<EFBFBD>ID,<EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ
delete gdm01 where FFromChild = 1
UPDATE gdm01 SET FNo = gda01c
select * into #gdm01 from gdm01 where 1=2
declare @CompNo VARCHAR(200)
declare #Companys cursor for
select distinct gae01c from gam05 where gae01c != '001'
open #Companys
fetch #Companys into @CompNo
while @@fetch_status=0
begin
delete #gdm01
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD>
--declare @CompNo VARCHAR(200)
-- select @compNo = '008'
insert #gdm01
select b.* from
(select gda01c,gda03c,FId from gdm01 where gda00c = '001') as a,
(select * from gdm01 where gda00c = @CompNo) as b
where (a.gda01c = b.gda01c )
and a.gda03c != b.gda03c
and b.gda01c + '.' + @CompNo not in (select gda01c from gdm01 where gda00c = '001')
update #gdm01 set FNo = gda01c + '.' + @CompNo
update a
set a.FNo = b.FNo
from gdm01 as a,#gdm01 as b
where a.gda00c = @CompNo
and a.gda01c = b.gda01c
update #gdm01 set gda01c = FNo ,gda00c = '001',FFromChild = 1
insert gdm01
select * from #gdm01
delete #gdm01
--<EFBFBD><EFBFBD>ȡ001<EFBFBD><EFBFBD>˾û<EFBFBD>е<EFBFBD>
insert #gdm01
select *
from gdm01
where gda00c = @CompNo
and gda01c not in (select gda01c from gdm01 where gda00c = '001')
update #gdm01 set gda00c = '001',FFromChild = 1
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>001<EFBFBD><EFBFBD>˾
INSERT gdm01
select * from #gdm01
fetch #Companys into @CompNo
end
close #Companys
deallocate #Companys
drop table #gdm01
update gdm01 set FCourseId =abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT))
--<EFBFBD><EFBFBD><EFBFBD>¸<EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>ID
update a
set a.FId = b.FId ,
a.FCourseId = b.FCourseId
FROM gdm01 AS A, (select FNo,FId,FCourseId from gdm01 where gda00c = '001') AS B
WHERE a.gda00c NOT IN('','001')
AND a.FNo = B.FNo
----------------------------
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ID,<EFBFBD>Ƴ<EFBFBD>ID,<EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ
delete gfm01 where FFromChild = 1
UPDATE gfm01 SET FNo = gfa01c
select * into #gfm01 from gfm01 where 1=2
-- declare @CompNo VARCHAR(200)
declare #Companys cursor for
select distinct gae01c from gam05 where gae01c != '001'
open #Companys
fetch #Companys into @CompNo
while @@fetch_status=0
begin
delete #gfm01
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD>
--declare @CompNo VARCHAR(200)
-- select @compNo = '008'
insert #gfm01
select b.* from
(select gfa01c,gfa03c,FId from gfm01 where gfa00c = '001') as a,
(select * from gfm01 where gfa00c = @CompNo) as b
where (a.gfa01c = b.gfa01c )
and a.gfa03c != b.gfa03c
and b.gfa01c + '.' + @CompNo not in (select gfa01c from gfm01 where gfa00c = '001')
update #gfm01 set FNo = gfa01c + '.' + @CompNo
update a
set a.FNo = b.FNo
from gfm01 as a,#gfm01 as b
where a.gfa00c = @CompNo
and a.gfa01c = b.gfa01c
update #gfm01 set gfa01c = FNo ,gfa00c = '001',FFromChild = 1
insert gfm01
select * from #gfm01
delete #gfm01
--<EFBFBD><EFBFBD>ȡ001<EFBFBD><EFBFBD>˾û<EFBFBD>е<EFBFBD>
insert #gfm01
select *
from gfm01
where gfa00c = @CompNo
and gfa01c not in (select gfa01c from gfm01 where gfa00c = '001')
update #gfm01 set gfa00c = '001',FFromChild = 1
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>001<EFBFBD><EFBFBD>˾
INSERT gfm01
select * from #gfm01
fetch #Companys into @CompNo
end
close #Companys
deallocate #Companys
drop table #gfm01
--<EFBFBD><EFBFBD><EFBFBD>¸<EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD>Ÿ<EFBFBD><EFBFBD><EFBFBD>ID
update a
set a.FId = b.FId
FROM gfm01 AS A, (select FNo,FId from gfm01 where gfa00c = '001') AS B
WHERE a.gfa00c NOT IN('','001')
AND a.FNo = B.FNo
--------------------------------------------------
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
select * into #gam10 from gam10 where 1=2
--declare @compNo varchar(10)
declare dbList cursor for
select distinct gae01c from gam05 where gae01c != '001'
open dbList
fetch dbList into @compNo
while @@fetch_status=0
begin
insert #gam10
select * FROM gam10 WHERE gak01c NOT IN(SELECT gak01c FROM gam10 WHERE gak00c = '001')
and gak00c = @compNo and gak01c not in (select gak01c from #gam10)
fetch dbList into @compNo
end
close dbList
deallocate dbList
UPDATE #gam10 SET gak00c = '001'
INSERT gam10
SELECT * FROM #gam10
DROP TABLE #gam10
update a
set a.FId = b.FId
FROM gam10 AS A, (select gak01c,FId from gam10 where gak00c = '001') AS B
WHERE a.gak00c NOT IN('','001')
AND a.gak01c = B.gak01c
END
ELSE
BEGIN
UPDATE gfm01 SET FNo = gfa01c
UPDATE gdm01 SET FNo = gda01c
END
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>001
/*
select * into #gam10 from gam10 where 1=2
declare @compNo varchar(10)
declare dbList cursor for
select distinct gae01c from gam05 where gae01c != '001'
open dbList
fetch dbList into @compNo
while @@fetch_status=0
begin
insert #gam10
select * FROM gam10 WHERE gak01c NOT IN(SELECT gak01c FROM gam10 WHERE gak00c = '001')
and gak00c = @compNo and gak01c not in (select gak01c from #gam10)
fetch dbList into @compNo
end
close dbList
deallocate dbList
UPDATE #gam10 SET gak00c = '001'
INSERT gam10
SELECT * FROM #gam10
drop table #gam10
*/
UPDATE A
SET A.FId = B.FId
FROM Gsm02 AS A,(SELECT gsb01c,gsb02c,FId FROM gsm02 WHERE gsb00c = '001') AS B
WHERE A.gsb00c != '001'
AND A.gsb01c = B.gsb01c
AND A.gsb02c = B.gsb02c
--<EFBFBD>½<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵĿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
INSERT gam10(gak00c,gak01c,gak02c,gak03i)
SELECT distinct'001', gca02c,'<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵĿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',1
FROM gcm01
WHERE gca00c = gca13d
AND gca01c NOT LIKE '<EFBFBD><EFBFBD>%'
AND gca02c NOT IN(select gak01c FROM gam10)
--<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FItemId = B.FId
FROM gdm01 AS B, hem01 AS A
WHERE B.gda00c = A.hea00c
AND A.hea01c = B.gda01c
--<EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FEmpId = B.FId
FROM hem02 AS A,ham01 AS B
WHERE A.heb01c = B.haa01c
AND A.heb00c = B.haa00c
UPDATE A
SET A.FItemID = B.FId
FROM hem02 AS A,gdm01 AS B
WHERE A.heb02c = B.gda01c
AND A.heb00c = B.gda00c
--<EFBFBD>ۿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FMasterId = B.FId
FROM gdm06 AS B,gdm07 AS A
WHERE B.gdf00c = A.gdg00c
AND B.gdf01c = A.gdg01c
AND b.gdf02c = A.gdg02c
--<EFBFBD><EFBFBD>Ŀ<EFBFBD>ۿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE gdm06
SET FItemId = gsm02.FId
FROM gsm02
WHERE gsb01c = 'L'
AND gsb00c = '001'
AND gsb02c = gdf01c
AND gdf02c = '1'
/*
EXEC PExecImportSQL '
UPDATE A
a SET A.FPayTypeId = B.FId
FROM {FDB}.gdm07 AS A,TPayAccount AS B
WHERE A.gdg11i = B.FBKAcctId */
-- AND a.gdg00c =''006''
-- '
UPDATE A
SET A.FCardTypeId = B.FId
FROM gdm07 AS A ,GAM10 AS B
WHERE A.gdg03c = B.gak01c
AND A.gdg00c = B.gak00c
--<EFBFBD><EFBFBD>Ʒ<EFBFBD>ۿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE gdm06
SET FItemId = gsm02.FId
FROM gsm02
WHERE gsb01c = 'J'
AND gsb00c = '001'
AND gsb02c = gdf01c
AND gdf02c = '2'
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FItemId = B.FId
FROM gfm05 AS A,gdm01 AS B
WHERE A.gfe01c = gda01c
AND a.gfe00c = gda00c
UPDATE A
SET A.FGoodsId = B.FId,
A.FUnitId = (SELECT FId FROM gsm02 WHERE gsb00c = '001' AND gsb01c = 'k' AND gsb02c = ISNULL(gfa08c,gfa07c))
FROM gfm05 AS A,gfm01 AS B
WHERE A.gfe02c = gfa01c
AND a.gfe00c = gfa00c
-----------------<EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>------------------
-----<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><EFBFBD>Ҫִ<EFBFBD>еڶ<EFBFBD><EFBFBD><EFBFBD>
-----------------<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>------------------
--<EFBFBD><EFBFBD><EFBFBD>»<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵİ󶨹<EFBFBD>ϵ
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD>ֲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>񵥾<EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>(ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>)
--select * from gcm03 where FMemId = '0'
--select * from gfm01 where FFromChild = 1
IF EXISTS(SELECT 1 FROM gcm06,gcm01
WHERE gcf00c = gca00c
AND gca00c = gca13d
AND gca01c = gcf01c
AND gcf02c NOT IN(SELECT gda01c FROM gdm01)
AND gcf02c != '')
BEGIN
SELECT 'ע<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD>, ִ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD>л<EFBFBD>Աʹ<EFBFBD><EFBFBD>'
SELECT GCM06.*
FROM gcm06,gcm01
WHERE gcf00c = gca00c
AND gca00c = gca13d
AND gca01c = gcf01c
AND gcf02c NOT IN(SELECT gda01c FROM gdm01)
AND gcf02c != ''
return
END
--<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FMemId = B.FMemId
FROM gcm01 AS B,gbm01 AS A
WHERE A.gba01c = B.gca04c
AND B.gca00c = B.gca13d
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FCardTypeId = B.FId
FROM gcm01 AS A,gam10 AS B
WHERE A.gca00c = A.gca13d
AND A.gca02c = B.gak01c
AND A.gca00c = B.gak00c
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UPDATE A
SET A.FCardTypeId = B.FId
FROM gcm01 AS A,gam10 AS B
WHERE A.gca00c = A.gca13d
AND A.gca02c = B.gak01c
AND '001'= B.gak00c --û<EFBFBD>е<EFBFBD>ȡ001
AND ISNULL(FCardTypeId,'0') = '0'
--<EFBFBD><EFBFBD>Ա<EFBFBD>˻<EFBFBD>
UPDATE A
SET A.FMemId = B.FMemId,
A.FCardId = B.FCardId
FROM gcm03 AS A,gcm01 AS B
WHERE A.gcc01c = B.gca01c
AND B.gca00c = B.gca13d
--<EFBFBD>Ƴ<EFBFBD>
UPDATE A
SET A.FMemId = B.FMemId,
A.FCardId = B.FCardId
FROM gcm06 AS A,gcm01 AS B
WHERE A.gcf01c = B.gca01c
AND B.gca00c = B.gca13d
--<EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD>ʷ
UPDATE A
SET A.FMemId = B.FMemId,
A.FCardId = B.FCardId
FROM gcm04 AS A,gcm01 AS B
WHERE A.gcd01c = B.gca01c
AND B.gca00c = B.gca13d
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ
UPDATE A
SET A.FMemId = B.FMemId,
A.FCardId = B.FCardId
FROM gcm20 AS A,gcm01 AS B
WHERE A.gct02c = B.gca01c
AND B.gca00c = B.gca13d
--<EFBFBD><EFBFBD>Ա<EFBFBD>Ƴ<EFBFBD>ID
UPDATE A
SET A.FItemId = B.FId,
A.FCourseId = B.FCourseId
FROM gcm06 AS A,gcm01 AS C,gdm01 AS B
WHERE A.gcf00c = C.gca00c
AND C.gca00c = C.gca13d
AND A.gcf01c = C.gca01c
AND A.gcf02c = B.gda01c
AND A.gcf00c = B.gda00c
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
EXEC ('IF OBJECT_ID(''dbo.TInventory'') IS NOT NULL
drop table dbo.TInventory')
EXEC ('create table dbo.TInventory
(
FCompNo VARCHAR(50) NOT NULL DEFAULT '''',
FGoodsId BIGINT NOT NULL DEFAULT 0,
goodsNo varchar(50),
goodsName varchar(50),
FStoreId BIGINT NOT NULL DEFAULT 0,
storeNo varchar(50),
storeName varchar(50),
goodsType varchar(50),
FPrice float,
FUnitId BIGINT NOT NULL DEFAULT 0,
cost varchar(50),
unit varchar(50),
quantity varchar(50),
amt_cost varchar(50),
FAmount float,
FQuantity float,
stattype varchar(50),
goodspec varchar(100),
)
CREATE NONCLUSTERED INDEX IX_INVENTORY ON dbo.TInventory(FGoodsId) ')
declare @CompNo VARCHAR(200)
declare @Today VARCHAR(20)
SELECT @Today = CONVERT(VARCHAR(20),GETDATE(),112)
PRINT @Today
declare #Companys cursor for
select distinct gae01c from gam05-- where gae01c = '001'
open #Companys
fetch #Companys into @CompNo
while @@fetch_status=0
begin
insert TInventory(goodsNo,goodsName,storeNo,storeName,goodsType,Fprice,cost,unit,quantity,amt_cost,FAmount,FQuantity,stattype)--,goodspec)
exec upg_stock_statistic @compNo,@Today,'*','','*','',5,0,'*','*','',0
UPDATE TInventory
SET FCompNo = @CompNo
WHERE FCompNo = ''
fetch #Companys into @CompNo
END
close #Companys
deallocate #Companys
UPDATE A
SET A.FGoodsId = B.FId
FROM TInventory AS A,gfm01 AS B
WHERE A.goodsNo = B.gfa01c
AND B.gfa00c = A.FCompNo
UPDATE A
SET A.FStoreId = B.FId
FROM TInventory AS A,gam04 AS B
WHERE A.storeNo = B.gad01c
AND gad00c = '001'
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-----------------------------------------------------------