如何使用SSIS插入新记录?我可以使用Exec SQL任务或OLE DB源SQL命令文本吗?

时间:2013-11-08 07:57:24

标签: sql-server sql-server-2008 ssis

我创建了一个名为DimInternationalFunction的表。

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[DimInternationalFunction]') AND type in (N'U'))
DROP TABLE [DimInternationalFunction]
Go
Create Table DimInternationalFunction
(IntFunctionKey int NOT NULL identity primary key,
SubSubFunctionString char(10),
FunctionCode char(3),
SubFunctionCode char(6),
SubSubFunctionCode char(10),
SubSubFunctionName nvarchar(60),
SubFunctionName nvarchar(60), 
FunctionName nvarchar(60))

我最初在SSMS中插入了此表中的记录。


在SSMS中手动插入初始记录后,现在我的经理要我使用SSIS插入“仅新记录”。

我已尝试在SSMS中使用它并且它有效。要么我插入了0条记录,要么有时会为我插入5条记录。我的经理要我在SSIS中这样做。

我尝试在数据访问模式下的OLE DB源中使用此脚本:SQL命令和SQL命令文本:

insert into DWResourceTask.dbo.DimInternationalFunction
select f.SubSubFunctionString,
f.FunctionCode,
f.SubFunctionCode,
f.SubSubFunctionCode,
f.SubSubFunctionName,
f.SubFunctionName, 
f.FunctionName
 from ODS_Function F
where FunctionViewCode = 'INT'
and not exists (select * from DWResourceTask.dbo.DimInternationalFunction I
                where (f.SubSubFunctionString=i.SubSubFunctionString
                        and f.FunctionCode=i.FunctionCode
                        and f.SubFunctionCode=i.SubFunctionCode
                        and f.SubSubFunctionCode=i.SubSubFunctionCode
                        and f.SubSubFunctionName=i.SubSubFunctionName
                        and f.SubFunctionName=i.SubFunctionName
                        and f.FunctionName=i.FunctionName)
)

点击预览后我收到的错误消息是

The component reported the following warnings:

Error at Int Function [International Function Table [33]]: No column information was returned by the SQL command.


Choose OK if you want to continue with the operation.
Choose Cancel if you want to stop the operation.

SSIS中是否有其他组件可以执行此操作?或者我可以只使用exec sql任务组件或ole db源?

我正在考虑使用连接到数据流任务的exec sql任务,在数据流任务中我将把包含临时表的ole db源放到那个或者有没有其他方法去做。请帮忙。提前谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用执行SQL任务执行此操作。

如果你想“纯粹的SSIS方式”,你可以使用查找组件。将“没有匹配的行”处理程序设置为“重定向到无匹配输出”,并将目标表配置为连接。然后仅使用“无匹配输出”,忽略“匹配输出”。并将“无匹配输出”中的记录发送到目标。

尽管有其名称,但在许多情况下,“Lookup”组件可用于过滤数据。

但我认为执行SQL任务对大型数据集更有效,将所有数据保留在数据库引擎中。