4

ssis パッケージにはString type variable V2式プロパティがあり、次の SQL クエリを書いています。

"select * from mytable where date = " + @[System::StartTime]

しかし、それは私にエラーを与えています:

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.

Attempt to set the result type of binary operation ""select * from table where date = " + @[System::StartTime]" failed with error code 0xC0047080.

私も試してみましたが、(DT_WSTR) @[System::StartTime] まだ運がありません。アドバイスはありますか?

4

1 に答える 1

4

StartTime 変数と [date] フィールドの両方のデータ型をクエリから文字列に変更する必要があります。これを試して:

"select * from mytable where convert( varchar(10), [date], 120) = '" + SUBSTRING((DT_WSTR,50)@[System::StartTime],1, 10) + "'"

適切なクエリを返す必要があります。

select * from mytable where convert( varchar(10), [date], 120) = '2013-05-22'

convert()「2013-05-22」のような文字列が返されます。私のシステム (DT_WSTR) では、キャスト@[System::StartTime]は文字列 "2013-05-22 16:14:43" を返しますが、他の設定がある場合、デフォルトの結果がたとえばの場合、dateparts から文字列を作成する必要があります。 「05/22/2013 16:14:43」は、他の地域設定によるものです。

使用している SQL サーバーのバージョンは何ですか? および[日付]フィールドタイプは正確ですか?

于 2013-05-22T14:23:07.957 に答える