0

SSIS パッケージを使用して動的に Excel ファイルを生成したい。私は次のように試しました:

私の変数は以下のようなSQLクエリを持っているので、私は中を 取りdata flow taskましたOledb Sourceoledb source editorconnection managerdata access mode = sql command from variableselect cusip,price,company from mytable where date in between @[var1] and @[var2]

しかし、私は使用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 上記の選択クエリを使用して、次のようなファイル名で毎日新しいExcelファイルを生成したいMYFile05222013 (with yesterdays date)

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.

ご意見をお聞かせください。

ここに画像の説明を入力

4

1 に答える 1

1

var3 を (日時ではなく) 文字列データ型にしてみてください。次のような式にします。

"select cusip,price,company from mytable where date in between " + @[User::var1] + " and " + @[User::var2]

var1 変数と var2 変数も文字列データ型にします。var1 と var2 を有効な日時値に解析するデフォルト値で設定します。

式の評価結果を表示するには、式ビルダーで [式の評価] をクリックします。

出力ファイルには、Excel の宛先が必要です。宛先接続マネージャーには、ファイル名の式があります。その式は、「MYFile05222013」のようなファイル名を作成する場所です。

于 2013-05-22T13:25:37.393 に答える