我正在寻找关于如何做某事的建议,我相当确定我应该能够使用SSIS。
我有两个数据库,我正在从表A更新表B,但是当我这样做时,我希望能够成功写入表B,将一些附加信息写入原始数据库中的日志表。 (见插图)
我不确定我会用什么控制来实现这个目标,但怀疑它可以在SSIS中完成。
答案 0 :(得分:0)
使用OLEDB转换对表B执行UPDATE,然后使用写入日志表的目标进行更新。
答案 1 :(得分:0)
在Ivan Starostin和其他人在董事会上提出建议后,我选择放弃使用SSIS执行此过程,并使用从网页背后的代码调用的存储过程来执行此功能。我在下面列举了插入流程SP的示例,因为我正在处理其余部分,但我想关闭这个问题。感谢Ivan和所有人的意见。 SSIS根本不是这种情况的最佳工具。我发现使用SP更加清洁。
USE [CInTracDB]
GO
/******** Object: StoredProcedure [dbo].[usp_InsertNewAssets] Script Date: 12/15/2016 3:00:00 PM *****/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Ken Carter>
-- Create date: <Dec 15, 2016>
-- Description: <Input Fields from Updates table, Insert all NEW records into CMDB.dbo.cmdb_assets, then copy record from
-- Updates to CInTracDB.dbo.Update_log, then Delete Record from Updates,
-- Return only sucesss / fail signal.
-- =============================================
CREATE PROCEDURE [dbo].[usp_InsertNewAssets](
@CAssetID as bigint,
@SubmitBy as varchar(50),
@SubmitDT as datetime,
@ApproveBy as varchar(50),
@Approved as char(10),
@ApprovedDT as datetime,
@Imported as char(10),
@ImportDT as datetime,
@AssetID as bigint,
@AssetType as int,
@AssetName as varchar(128),
@AssetShortDesc as varchar(50),
@AssetLongDesc as varchar(200),
@AssetAddNotes as varchar(254),
@AssetManuf as varchar(50),
@AssetModel as varchar(50),
@AssetTag as varchar(20),
@AssetAcqDate as datetime,
@AssetDTAssetID as varchar(20),
@AssetLocGrp as varchar(10),
@AssetLoc1 as varchar(8),
@AssetLoc2 as varchar(8),
@AssetLoc3 as varchar(8),
@AssetParent as bigint,
@AssetStatus as int,
@AssetPropType as int,
@AssetPrimUser as varchar(20),
@AssetEntered as datetime,
@AssetEnteredBy as varchar(50),
@AssetOwner as varchar(50),
@AssetCompany as varchar(10),
@AssetPriIPAddr as varchar(15),
@AssetPriMACAddr as varchar(17),
@AssetPriOS as varchar(20),
@AssetPriOSSP as varchar(20),
@AssetNotes as varchar(500),
@AssetAdminGrp as varchar(100),
@AssetSerialNum as varchar(75),
@AssetOperType as int,
@AssetOperStatus as int
)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @AssetFACL as bit = 0
DECLARE @AssetStatVer as bit = 0
BEGIN
INSERT INTO CMDB.dbo.cmdb_assets (AssetType, AssetName, AssetShortDesc, AssetLongDesc, AssetAddNotes, AssetManuf,
AssetModel, AssetTag, AssetAcqDate, AssetDTAssetID, AssetLocGrp, AssetLoc1, AssetLoc2, AssetLoc3, AssetParent,
AssetStatus, AssetPropType, AssetPrimUser, AssetEntered, AssetEnteredBy, AssetOwner, AssetCompany, AssetPriIPAddr,
AssetPriMACAddr, AssetPriOS, AssetPriOSSP, AssetNotes, AssetAdminGrp, AssetSerialNum, AssetOperType,
AssetOperStatus, AssetFACL, AssetStatVer)
SELECT AssetType, AssetName, AssetShortDesc, AssetLongDesc, AssetAddNotes, AssetManuf, AssetModel, AssetTag,
AssetAcqDate, AssetDTAssetID, AssetLocGrp, AssetLoc1, AssetLoc2, AssetLoc3, AssetParent, AssetStatus, AssetPropType,
AssetPrimUser, AssetEntered, AssetEnteredBy, AssetOwner, AssetCompany, AssetPriIPAddr, AssetPriMACAddr, AssetPriOS,
AssetPriOSSP, AssetNotes, AssetAdminGrp, AssetSerialNum, AssetOperType, AssetOperStatus
FROM Updates
WHERE AssetID > 0
END
BEGIN
Insert INTO Update_log (CAssetID, SubmitBy, SubmitDT, ApproveBy, Approved, ApprovedDT, Imported, ImportDT, AssetID,
AssetType, AssetName, AssetShortDesc, AssetLongDesc, AssetAddNotes, AssetManuf, AssetModel, AssetTag, AssetAcqDate,
AssetDTAssetID, AssetLocGrp, AssetLoc1, AssetLoc2, AssetLoc3, AssetParent, AssetStatus, AssetPropType,
AssetPrimUser, AssetEntered, AssetEnteredBy, AssetOwner, AssetCompany, AssetPriIPAddr, AssetPriMACAddr, AssetPriOS,
AssetPriOSSP, AssetNotes, AssetAdminGrp, AssetSerialNum, AssetOperType, AssetOperStatus)
SELECT AssetType, AssetName, AssetShortDesc, AssetLongDesc, AssetAddNotes, AssetManuf, AssetModel, AssetTag,
AssetAcqDate, AssetDTAssetID, AssetLocGrp, AssetLoc1, AssetLoc2, AssetLoc3, AssetParent, AssetStatus, AssetPropType,
AssetPrimUser, AssetEntered, AssetEnteredBy, AssetOwner, AssetCompany, AssetPriIPAddr, AssetPriMACAddr, AssetPriOS,
AssetPriOSSP, AssetNotes, AssetAdminGrp, AssetSerialNum, AssetOperType, AssetOperStatus
FROM Updates
WHERE AssetID > 0
END
BEGIN
DELETE FROM Updates
WHERE (AssetID > 0)
END
END
GO