SSIS从A表中获取不在B表中的所有数据并将其插入表B中

时间:2014-11-09 12:44:30

标签: mysql sql-server ssis

我有两个表,我需要创建SSIS包“数据流任务”

表A和表B,我需要创建SSIS包,始终将表A中不在表B中的数据插入到表B中(基于A中的badgeno和B中的badgeno_ID)。任何想法和帮助PLZ?

CREATE TABLE [dbo].[A](
    [firstname] [nvarchar](100) NULL,
    [mobile] [nvarchar](50) NULL,
    [note] [nvarchar](500) NULL,
    [city] [nvarchar](255) NULL,
    [badgeno] [nvarchar](50) NULL,
    [lastname] [nvarchar](100) NULL
) ON [PRIMARY]

GO



CREATE TABLE [dbo].[B](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [FirstName] [nvarchar](100) NULL,
    [LastName] [nvarchar](100) NULL,
    [DateOfBirth] [datetime] NULL,
    [FirmID] [int] NULL,
    [Phone] [varchar](50) NULL,
    [Mobile] [varchar](50) NULL,
    [EMail] [nvarchar](100) NULL,
    [EmployeeNr] [nvarchar](10) NULL,
    [Note] [nvarchar](500) NULL,
    [PhonePrivate] [varchar](50) NULL,
    [StreetAddress] [nvarchar](255) NULL,
    [Zip] [nvarchar](20) NULL,
    [City] [nvarchar](255) NULL,
    [Data] [nvarchar](500) NULL,
    [UserName] [nvarchar](50) NULL,
    [Password] [nvarchar](50) NULL,
    [ADGUID] [nvarchar](50) NULL,
    [Language] [nvarchar](50) NULL,
    [Theme] [nvarchar](30) NULL,
    [DefaultZone] [int] NULL,
    [Bed] [nvarchar](50) NULL,
    [badgeNO_ID] [nvarchar](50) NULL,
    [RegisteredBy] [nvarchar](50) NOT NULL,
    [Registered] [datetime] NOT NULL,
    [LastUpdatedBy] [nvarchar](50) NOT NULL,
    [LastUpdated] [datetime] NOT NULL,
    [DefaultView] [nvarchar](50) NULL,
    [ExpandTagList] [bit] NULL,
    [PrintEmergencyReport] [bit] NULL,
    [EmergencyReportPath] [nvarchar](255) NULL)

2 个答案:

答案 0 :(得分:0)

拖放Execute Sql Task并将以下t-sql查询放入其中。乔布斯一个gooden。

INSERT INTO [dbo].[B] 
                  ([firstname] , [mobile], [note], [City], [badgeNO_ID] , [LastName])
SELECT [A].[firstname] 
     , [A].[mobile]
     , [A].[note]
     , [A].[City]
     , [A].[badgeno] 
     , [A].[LastName]
FROM [dbo].[A] 
WHERE NOT EXISTS (SELECT 1 
                  FROM [dbo].[B]
                  WHERE [dbo].[A].[badgeno] = [dbo].[B].[badgeNO_ID])

答案 1 :(得分:0)