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'。

1 つのストアド プロシージャで複数のテーブルに複数のデータを転送するためのストアド プロシージャを作成するためのソリューションを見つけようとしていますが、それが可能かどうか知りたいですか? または、これに対する解決策があるかどうか..

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 に答える