如何建立EXCEL表,导入SQL临时表,并运下列脚本?
我在网上得到以下语句,导入前的原始档案请用Excel(表头项目是什么?)做好,并将这些档案导入到SQL的临时数据中(如何导入,保存为什么表名),在运行相应的脚本(如何运行...
我在网上得到以下语句,导入前的原始档案请用Excel(表头项目是什么?)做好,并将这些档案导入到SQL的临时数据中(如何导入,保存为什么表名),在运行相应的脚本(如何运行?)。
库存期初数据导入脚本
use ufdata_001_2004
--delete from RdRecords --delete from RdRecord
--系统变量定义 declare @rec_num int, @rec_max int, @cInCode varchar(10)
set @cInCode = (select Max(cIncode) from MaxVouch where cVouch='收发主表ID')
--select @cInCode as 'cInCode'
SET IDENTITY_INSERT MaxVouch ON
if @cInCode is NULL begin declare @cmaxid varchar(10)
set @cmaxid = (select max(ID) as ID from MaxVouch)
insert into MaxVouch(ID,cVouch,cWhCode,cStation,cInCode) values(@cmaxid+1,'收发主表ID',NULL,NUll,0) insert into MaxVouch(ID,cVouch,cWhCode,cStation,cInCode) values(@cmaxid+2,'收发子表ID',NULL,NUll,0) set @cInCode = 0
end
--RdRecode表变量定义 declare @ID int, @cWhCode varchar(10)
--RdRecodes表变量定义 declare @cinvCode varchar(20), @iQUANTITY float, @iUnitCost float, @iPrice money
--存货期初导入主程序
--清除RdRecord主表和子表 set @rec_num = (select count(*) as 'max' from RdRecords) if @rec_num > 0 begin delete from rdrecords delete from rdrecord update MaxVouch set cincode=0 where cVouch='收发主表ID' update MaxVouch set cincode=0 where cVouch='收发子表ID' end
--定义光标 declare sql_cursor cursor for select [cWhcode],[cInvCode],[iQuantity],[iUnitCost],[iPrice] from [tempdb].[dbo].[records] where cInvCode in (select cInvCode from ufdata_001_2004.dbo.inventory) --打开光标 open sql_cursor
--获取最大单据号 set @cInCode = (select Max(cIncode) from MaxVouch where cVouch='收发主表ID')
--获取数据并移动光标 FETCH NEXT FROM SQL_Cursor into @cWhcode,@cInvCode,@iQuantity,@iUnitCost,@iPrice WHILE @@FETCH_STATUS = 0 BEGIN
set @cInCode=@cInCode+1 set @ID = @cInCode
--更新记录数 update MaxVouch set cincode=@cIncode where cVouch='收发主表ID' update MaxVouch set cincode=@cIncode where cVouch='收发子表ID'
--写入RDRecord表 Insert into RdRecord ( ID, bRdFlag, cWhCode, dDate, cDepCode, cPersonCode, cVenCode, cVouchType, cSource, cCode, cHandler, cDefine1, cDefine2, cDefine3, cDefine4, cDefine5, cDefine6, cDefine7, cDefine8, cDefine9, cDefine10) values ( @id, 1, @cWhCode, '2004-11-30', Null, Null, Null, '34', '存货', @ID * -1, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null)
--写入RDRecords表 Insert into RdRecords ( Autoid, ID, cInvCode, IQUANTITY, iNum, iUnitCost, iPrice, cBatch, cFree1, cFree2, dVdate, citem_class, citemcode, cDefine22, cDefine23, cDefine24, cDefine25, cDefine26, cDefine27) values ( @id, @id, @cInvCode, @IQUANTITY, Null, @iUnitCost, @iPrice, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null)
--移动光标 FETCH NEXT FROM SQL_Cursor into @cWhcode,@cInvCode,@iQuantity,@iUnitCost,@iPrice END
CLOSE SQL_cursor DEALLOCATE SQL_cursor 展开
库存期初数据导入脚本
use ufdata_001_2004
--delete from RdRecords --delete from RdRecord
--系统变量定义 declare @rec_num int, @rec_max int, @cInCode varchar(10)
set @cInCode = (select Max(cIncode) from MaxVouch where cVouch='收发主表ID')
--select @cInCode as 'cInCode'
SET IDENTITY_INSERT MaxVouch ON
if @cInCode is NULL begin declare @cmaxid varchar(10)
set @cmaxid = (select max(ID) as ID from MaxVouch)
insert into MaxVouch(ID,cVouch,cWhCode,cStation,cInCode) values(@cmaxid+1,'收发主表ID',NULL,NUll,0) insert into MaxVouch(ID,cVouch,cWhCode,cStation,cInCode) values(@cmaxid+2,'收发子表ID',NULL,NUll,0) set @cInCode = 0
end
--RdRecode表变量定义 declare @ID int, @cWhCode varchar(10)
--RdRecodes表变量定义 declare @cinvCode varchar(20), @iQUANTITY float, @iUnitCost float, @iPrice money
--存货期初导入主程序
--清除RdRecord主表和子表 set @rec_num = (select count(*) as 'max' from RdRecords) if @rec_num > 0 begin delete from rdrecords delete from rdrecord update MaxVouch set cincode=0 where cVouch='收发主表ID' update MaxVouch set cincode=0 where cVouch='收发子表ID' end
--定义光标 declare sql_cursor cursor for select [cWhcode],[cInvCode],[iQuantity],[iUnitCost],[iPrice] from [tempdb].[dbo].[records] where cInvCode in (select cInvCode from ufdata_001_2004.dbo.inventory) --打开光标 open sql_cursor
--获取最大单据号 set @cInCode = (select Max(cIncode) from MaxVouch where cVouch='收发主表ID')
--获取数据并移动光标 FETCH NEXT FROM SQL_Cursor into @cWhcode,@cInvCode,@iQuantity,@iUnitCost,@iPrice WHILE @@FETCH_STATUS = 0 BEGIN
set @cInCode=@cInCode+1 set @ID = @cInCode
--更新记录数 update MaxVouch set cincode=@cIncode where cVouch='收发主表ID' update MaxVouch set cincode=@cIncode where cVouch='收发子表ID'
--写入RDRecord表 Insert into RdRecord ( ID, bRdFlag, cWhCode, dDate, cDepCode, cPersonCode, cVenCode, cVouchType, cSource, cCode, cHandler, cDefine1, cDefine2, cDefine3, cDefine4, cDefine5, cDefine6, cDefine7, cDefine8, cDefine9, cDefine10) values ( @id, 1, @cWhCode, '2004-11-30', Null, Null, Null, '34', '存货', @ID * -1, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null)
--写入RDRecords表 Insert into RdRecords ( Autoid, ID, cInvCode, IQUANTITY, iNum, iUnitCost, iPrice, cBatch, cFree1, cFree2, dVdate, citem_class, citemcode, cDefine22, cDefine23, cDefine24, cDefine25, cDefine26, cDefine27) values ( @id, @id, @cInvCode, @IQUANTITY, Null, @iUnitCost, @iPrice, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null)
--移动光标 FETCH NEXT FROM SQL_Cursor into @cWhcode,@cInvCode,@iQuantity,@iUnitCost,@iPrice END
CLOSE SQL_cursor DEALLOCATE SQL_cursor 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询