我想使用SSIS包生成动态excel文件。 我尝试过如下:
在data flow task
我Oledb Source
内oledb source editor
在connection manager
data access mode = sql command from variable
下,因为我的变量有select cusip,price,company from mytable where date in between @[var1] and @[var2]
下面的SQL查询
但是我没有使用var1
和var 2
它给我解析错误。
在ssis项目中创建了3个变量
var1 datatype = datetime value=5/01/2011 8:22:10 AM
var2 datatype = datetime value=5/21/2011 8:22:10 AM
var3 datatype = datetime value=MY ABOVE SELECT QUERY
使用上面的选择查询我想每天使用MYFile05222013
(with yesterdays date)
等文件名生成新的Excel文件
var 3 taken as string and added value into Expression
但是得到解析错误:
Error code: 0x80040E14.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80040E14 Description: "Statement(s) could not be prepared.".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80040E14 Description: "Must declare the scalar variable "@".".
和
The data types "DT_WSTR" and "DT_DATE" are incompatible for binary operator "+". The operand types could not be implicitly cast into compatible types for the operation. To perform this operation, one or both operands need to be explicitly cast with a cast operator.
请建议。
答案 0 :(得分:1)
尝试将var3设为字符串数据类型(而不是日期时间)。给它一个这样的表达式:
"select cusip,price,company from mytable where date in between " + @[User::var1] + " and " + @[User::var2]
也使var1和var2变量成为字符串数据类型。使用可解析为有效日期时间值的默认值设置var1和var2。
要查看表达式的评估结果,请单击Evaluate Expression in the Expression Builder.
对于输出文件,您需要一个Excel目标。目标连接管理器将具有文件名的表达式。您可以在该表达式中构建“MYFile05222013”等文件名。