2010-07-22 211 views
2

我想在一个表中插入一个SSIS包中的几个变量。ssis - 将变量值插入表中

例如: -

@financialMonth, @Status, @Comments 

变量已经被沿途基于查找,文件名,日期等值填充,我想将它们存储在一个结果表。

正在使用执行SQL任务的方式来做到这一点?

我是否需要调用sproc并将这些变量作为参数传递?

我试图把下面的T-SQL到的SQLStatement属性

INSERT INTO FilesProcessed 
    (ProcessedOn, ProviderCode, FinancialMonth, 
    FileName, Status, Comments) 
SELECT  GETDATE(), 'ABC' , 201006, 
    'ABC_201005_Testology.csv', 
    'Imported','Success' 

我试图硬编码上述值来得到它的工作

这些都是在桌子上我的列米插入

Column_name  Type   Computed Length 
fileID   int   no   4 
ProcessedOn  datetime  no   8 
ProviderCode nchar  no   6 
FinancialMonth int   no   4 
FileName  nvarchar  no  510 
Status   nvarchar  no   40 
Comments  nvarchar  no  510 

这是表达代码馈送SQLStatementSource属性

"INSERT INTO FilesProcessed (ProcessedOn, ProviderCode, FinancialMonth, 
    FileName, Status, Comments) SELECT  GETDATE() AS ProcessedOn, '" 
    + @[User::providerCode] + "' , " 
    + (DT_STR,6,1252)@[User::financialMonth] + ", '" 
    + @[User::fileName] + "', 'Imported' AS Status,'Successfully' AS Comments " 

不幸的是,我失去了一些东西,并不能完全得到它的工作。

The Error message I'm getting is ... Error: 0xC002F210 at Log entry in FilesProcessed, Execute SQL Task: Executing the query "INSERT INTO FilesProcessed (ProcessedOn, ProviderCode, FinancialMonth, FileName, Status, Comments) SELECT
GETDATE(), 'ABC' , 201006, 'DAG_201005_Testology.csv', 'Imported','Successfully'" failed with the following error: "An error occurred while extracting the result into a variable of type (DBTYPE_I2)". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

一)。建议执行SQL任务是否是我想做的事情。 b)。给我任何指示或陷阱来寻找和检查。

在此先感谢。

+2

这看起来应该从我记得关于SSIS的工作。 (尽管显然你发布的代码根本不使用变量)你得到了什么错误? – 2010-07-22 12:32:46

+0

尝试删除“作为状态”和“作为评论” – 2010-07-22 13:32:04

+0

我粘贴了用于创建T-SQL的表达式代码。我试图对T-SQL进行硬编码以查看更简单的代码是否工作。 – cometbill 2010-07-22 14:04:08

回答

4

OK,这里是我做的。

我创建了一个执行SQL任务和配置,从而: -

General Tab 
    ConnectionType = OLE DB 
    SQLSourceType = Direct Input 
    SQLStatement = (left blank) 
    BypassPrepare = True 
    ResultSet = None 

Parameter Mapping 
    (none - leave blank) 

Result Set 
    (none - leave blank) 

Expressions 
    SQLStatementSource = "INSERT INTO FilesProcessed (ProcessedOn, ProviderCode, FinancialMonth, FileName, Status, Comments) SELECT GETDATE(), '" + @[User::providerCode] + "' , " + (DT_STR,6,1252)@[User::financialMonth] + ", '" + @[User::fileName] + "', 'Import - Success', '" + @[User::fileComments] + "'" 

这时只要我设置的变量和变量窗口填充它们(表达式编辑器不会让你保存的表达式引用一个不存在的变量保留记事本,方便存储内容,同时返回并编辑变量窗口,并添加新的变量;)

缓慢地构建表达式,使用Parse表达式按钮定期检查。

0

一对夫妇的投机建议

  1. 该错误消息表示,而提取结果成型的(DBTYPE_I2)可变时发生错误。但这是一个直接的插入语句。除受影响的行之外,不应该有结果。你有任何参数映射错误地设置为Output

  2. 如果您尝试直接在管理工作室中从错误消息中运行SQL查询,该怎么办?这会给你一个错误吗?

0

在上述表定义FinancialMonth作为int数据类型作为

FinancialMonth int无4

而inseting铸造作为

(DT_STR,6,1252)@ [用户:: financialMonth]

我觉得它纯粹是一种数据类型mism atch与目标表定义。

感谢

prav