1
BEGIN
IF @TransType = 1
BEGIN
       SET IDENTITY_INSERT [dbo].[Sales.DeletedDeliveryHeaderHistory] ON 

       -- INSERT TO DELETE DELIVERY HEADER HISTORY
       INSERT INTO @DRHeaderHist (RowID, CompanyName, ItemClassCode, DeliveryDate,
                                  LoadingDate, DRNumber, Custnmbr, CustName,    
                                  TruckerID, PlateNumberID, TonnerID, DeliveryTypeID,
                                  Remarks, DateCreated, DateModified, DatePosted, 
                                  UserName, FGUserName, DRUserName, PostedFG, 
                                  Import, CareOf, CareOfName )
           SELECT * 
           FROM [Sales.DeliveryHeaderHistory] 
           WHERE DRNUMBER = @DR

       INSERT INTO dbo.Sales.DeletedDeliveryHeaderHistory (RowID, CompanyName, 
                       ItemClassCode,  DeliveryDate, LoadingDate, DRNumber, Custnmbr, 
                       CustName, TruckerID, PlateNumberID, TonnerID, DeliveryTypeID,
                       Remarks, DateCreated, DateModified, DatePosted, UserName, 
                       FGUserName, DRUserName, PostedFG, Import, CareOf, CareOfName )
           SELECT * 
           FROM @DRHeaderHist

SET IDENTITY_INSERT [dbo].[Sales.DeletedDeliveryHeaderHistory] OFF 
SET IDENTITY_INSERT [dbo].[Sales.DeletedDeliveryDetailsHistory] ON 

-- INSERT TO DELETE DELIVERY DETAIL HISTORY

INSERT INTO @DRDetailsHist ( RowID, CompanyName, DRNumber, OrderDocNum, OFLineNumber, LineNumber, Quantity, UofM, KgsPerBag, Itemnmbr,
                                                  TotalKgs, ItemDesc, VariantCode, VariantDesc, ProductionCode, OrderDate, DateNeeded, Week, Month1, PostedFG )
SELECT * from [dbo].[Sales.DeliveryDetailsHistory] WHERE DRNUMBER = @DR


INSERT INTO [dbo].[Sales.DeletedDeliveryDetailsHistory] ( RowID, CompanyName, DRNumber, OrderDocNum, OFLineNumber, LineNumber, Quantity, UofM, KgsPerBag, Itemnmbr,
                                                  TotalKgs, ItemDesc, VariantCode, VariantDesc, ProductionCode, OrderDate, DateNeeded, Week, Month, PostedFG )
SELECT * FROM @DRDetailsHist

SET IDENTITY_INSERT [dbo].[Sales.DeletedDeliveryDetailsHistory] OFF 
END
END

这在存储过程查询中是否可能,因为我收到错误

消息 208,级别 16,状态 1,过程 SFC_spTransferDRtoDeleteArchives,第 85 行
无效的对象名称“dbo.Sales.DeletedDeliveryHeaderHistory”。

我正在尝试找到一种解决方案,用于在一个存储过程中为多个表上的多个数据传输创建存储过程,只是想知道它是否可能?或者可能有解决方案。

4

1 回答 1

1

此脚本中有语法错误。 我不知道你为什么要在表格的名称中嵌入句点。您需要更明智地使用方括号:

IF @TransType = 1

BEGIN

SET IDENTITY_INSERT [dbo].[Sales.DeletedDeliveryHeaderHistory] ON 

-- INSERT TO DELETE DELIVERY HEADER HISTORY

INSERT INTO @DRHeaderHist (RowID, CompanyName, ItemClassCode, DeliveryDate, LoadingDate, DRNumber, Custnmbr, CustName,  TruckerID, PlateNumberID, TonnerID, DeliveryTypeID,
                            Remarks, DateCreated, DateModified, DatePosted, UserName, FGUserName, DRUserName, PostedFG, Import, CareOf, CareOfName )
SELECT * from [Sales.DeliveryHeaderHistory] WHERE DRNUMBER = @DR



----------------v
INSERT INTO dbo.[Sales.DeletedDeliveryHeaderHistory] (RowID, CompanyName, ItemClassCode,  DeliveryDate, LoadingDate, DRNumber, Custnmbr, CustName, TruckerID, PlateNumberID, TonnerID, DeliveryTypeID,
                                                  Remarks, DateCreated, DateModified, DatePosted, UserName, FGUserName, DRUserName, PostedFG, Import, CareOf, CareOfName )
SELECT * FROM @DRHeaderHist

SET IDENTITY_INSERT [dbo].[Sales.DeletedDeliveryHeaderHistory] OFF 
SET IDENTITY_INSERT [dbo].[Sales.DeletedDeliveryDetailsHistory] ON 

-- INSERT TO DELETE DELIVERY DETAIL HISTORY

INSERT INTO @DRDetailsHist ( RowID, CompanyName, DRNumber, OrderDocNum, OFLineNumber, LineNumber, Quantity, UofM, KgsPerBag, Itemnmbr,
                                                  TotalKgs, ItemDesc, VariantCode, VariantDesc, ProductionCode, OrderDate, DateNeeded, Week, Month1, PostedFG )
SELECT * from [dbo].[Sales.DeliveryDetailsHistory] WHERE DRNUMBER = @DR




INSERT INTO [dbo].[Sales.DeletedDeliveryDetailsHistory] ( RowID, CompanyName, DRNumber, OrderDocNum, OFLineNumber, LineNumber, Quantity, UofM, KgsPerBag, Itemnmbr,
                                                  TotalKgs, ItemDesc, VariantCode, VariantDesc, ProductionCode, OrderDate, DateNeeded, Week, Month, PostedFG )
SELECT * FROM @DRDetailsHist

SET IDENTITY_INSERT [dbo].[Sales.DeletedDeliveryDetailsHistory] OFF 

END

我注意到需要方括号的地方。

于 2013-07-20T02:50:02.457 回答