简体   繁体   中英

Query to filter the data in ODBC Source SSIS using variable

I'm writing the source query in ODBC source to filter the records on a column (nvarchar) to pull the incremental load.

In the SouceCodeExpression I wrote the following code.

"Select * from Source_AuthorizationHistory where UpdateDate >" + "'@[User::LastUpdate]'"

Here UpdateDate is nvarchar datatype coming from source, I have to filter the records from source based on the last updated date in the target. So, here @[User::LastUpdate] variable datatype is String

@[User::LastUpdate] = Select Convert(nvarchar,Cast((Max(ETL_updated)-1) as Date)) as LastUpdated from Target_AUTHORIZATIONHISTORY

Help me to write this source query expression

"Select * from Source_AuthorizationHistory where UpdateDate >" + "'@[User::LastUpdate]'"

I got the following error ErrorCode

Assuming your value for @[User::LastUpdate] is correct

You have this:

"Select * from Source_AuthorizationHistory where UpdateDate >" + "'@[User::LastUpdate]'"

You need to do this:

"Select * from Source_AuthorizationHistory where UpdateDate > (" +  @[User::LastUpdate] + ")"

as this expression will equate to this:

Select * from Source_AuthorizationHistory where UpdateDate > (Select Convert(nvarchar,Cast((Max(ETL_updated)-1) as Date)) as LastUpdated from Target_AUTHORIZATIONHISTORY)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM