简体   繁体   中英

Data not getting fetched from Source using ODBC Connection and passing the SQL Query from a variable

I have a source query, wherein I am fetching data from Horton using ODBC connection

Select * from Table1 Where CreationDate > '2020-09-24 00:00:001'

When I run this query manually it runs fine, but when I run my SSIS Package no data is being fetched.

Please note I am passing this SQL Query from a variable and all variables are correctly passed. I have checked it using Edit Breakpoints.

This are the steps I followed to pass the query from a variable

The issue with your query appears to be the default formatting for translating an SSIS DateTime type to a string representation. The ODBC source appears to need a YYYY-MM-DD hh:mm:ss:mss (where mss is milliseconds but not the correct format code).

I tend to break my long expression into multiple variables and then have a "simple" final form that puts them all together.

Date_YYYYMMDD -> (DT_WSTR, 4)  YEAR(@[System::ContainerStartTime]) + "-" + RIGHT("0" + (DT_WSTR, 2)  MONTH(@[System::ContainerStartTime]),2)  + "-" + RIGHT("0" + (DT_WSTR, 2)  DAY(@[System::ContainerStartTime]),2)

That builds my YYYY-MM-DD format string. Data type is String

Date_HHMMSSms -> RIGHT("0" + (DT_WSTR, 2) DATEPART( "Hour", @[System::ContainerStartTime] ),2) + ":" +  RIGHT("0" + (DT_WSTR, 2) DATEPART( "Minute", @[System::ContainerStartTime] ),2) + ":" +  RIGHT("0" + (DT_WSTR, 2) DATEPART( "Second", @[System::ContainerStartTime] ),2) + ":" +  RIGHT("0" + (DT_WSTR, 3) DATEPART( "Millisecond", getdate() ),3)

This builds out the time component. I always advocate for using the System variable ContainerStartTime instead of GETDATE() as getdate is evaluated every time we access it while container start time is constant for the execution of a package. What I discovered and can't wait to blog about is the the expression language doesn't appear to get the milliseconds out of a ContainerStartTime but does work correctly for GETDATE() calls.

The final date variable then becomes something like

Date_Filter -> @[User::Date_YYYYMMDD] + " " + @[User::Date_HHMMSSms]

Which then makes my query usage look like

Query_Source -> "Select * from Table1 Where CreationDate > '" + @[User::Date_Filter] + "'"

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