Notifications

13 views

Description

When customer using JDBC datasources, configure a SQL query to run on the Source DB Server.

In this SQL query if customer has Order By clause, there are following scenarios.

1. When Checkbox for Use Lastrun datetime is set to False

2. When Checkbox for Use Lastrun datetime is set to True


In Scenario 1 there is no issue observed.

In Scenario 2 when User Last run datetime is set to True and customer also uses Order By clause in the SQL query, it throws an error - "SQL command not properly ended".

Cause

When we run the datasource (Order By clause in SQL Statement and User Last run DateTime option set to true), system appends Order By '<Last_run_datetime field> clause at the end of the sql statement. Causing 2 Order By clause.


e.g - 

if original sql statement with order by clause is - 

SELECT
CUR.ISO_CODE,
EX.SDL_ID,
EX.FACTOR / USD.FACTOR AS FACTOR_USD,
EX.ACTIVE_FROM_DATE ,
EX.ACTIVE_TO_DATE,
to_char(EX.MDM_INTERFACE_UPDATE_TIMESTAMP) as LAST_UPDATE,
EX.MDM_INTERFACE_UPDATE_TIMESTAMP
FROM MDM.MV_CUR_CURRENCY CUR,
MDM.MV_CUR_EXCHANGE_RATE EX,
(SELECT BASE_CURRENCY_SDL_ID,
EX.ACTIVE_FROM_DATE,
EX.ACTIVE_TO_DATE,
FACTOR
FROM MDM.MV_CUR_EXCHANGE_RATE EX, MDM.MV_CUR_CURRENCY CUR
WHERE EX.BASE_CURRENCY_SDL_ID = CUR.SDL_ID
AND CUR.ISO_CODE = 'USD'
AND EXCHANGE_RATE_TYPE_CODE = 'QQ') USD
WHERE CUR.SDL_ID = EX.BASE_CURRENCY_SDL_ID
AND EX.ACTIVE_FROM_DATE = USD.ACTIVE_FROM_DATE
AND EX.ACTIVE_TO_DATE = USD.ACTIVE_TO_DATE
AND EX.EXCHANGE_RATE_TYPE_CODE = 'QQ'
AND EX.MDM_INTERFACE_UPDATE_TIMESTAMP >= '30-JUN-20 01.00.36.000000 AM'
ORDER BY EX.MDM_INTERFACE_UPDATE_TIMESTAMP ASC

Then SQL statement resulting due to Use Last run datetime is - 

SELECT
CUR.ISO_CODE,
EX.SDL_ID,
EX.FACTOR / USD.FACTOR AS FACTOR_USD,
EX.ACTIVE_FROM_DATE ,
EX.ACTIVE_TO_DATE,
to_char(EX.MDM_INTERFACE_UPDATE_TIMESTAMP) as LAST_UPDATE,
EX.MDM_INTERFACE_UPDATE_TIMESTAMP
FROM MDM.MV_CUR_CURRENCY CUR,
MDM.MV_CUR_EXCHANGE_RATE EX,
(SELECT BASE_CURRENCY_SDL_ID,
EX.ACTIVE_FROM_DATE,
EX.ACTIVE_TO_DATE,
FACTOR
FROM MDM.MV_CUR_EXCHANGE_RATE EX, MDM.MV_CUR_CURRENCY CUR
WHERE EX.BASE_CURRENCY_SDL_ID = CUR.SDL_ID
AND CUR.ISO_CODE = 'USD'
AND EXCHANGE_RATE_TYPE_CODE = 'QQ') USD
WHERE CUR.SDL_ID = EX.BASE_CURRENCY_SDL_ID
AND EX.ACTIVE_FROM_DATE = USD.ACTIVE_FROM_DATE
AND EX.ACTIVE_TO_DATE = USD.ACTIVE_TO_DATE
AND EX.EXCHANGE_RATE_TYPE_CODE = 'QQ'
AND EX.MDM_INTERFACE_UPDATE_TIMESTAMP >= '30-JUN-20 01.00.36.000000 AM'
ORDER BY EX.MDM_INTERFACE_UPDATE_TIMESTAMP ASC
ORDER BY <Last_run_datetime_time>

The 2 ORDER BY clauses in the SQL statement cause an error - SQL command not properly ended".

Resolution

Users don't really need to add Order By clause to the SQL Statement, as when you run the Load All Data, backend code appends the ORDER BY <Last_run_datetime_field> clause to the end of SQL Statement by default.

Please note - Running Load 20 records doesn't add the ORDER BY clause to the SQL statement.

So to the crux of it, Using ORDER BY clause to the SQL statement + Use of "Use last run datetime" is not possible.

Article Information

Last Updated:2020-09-07 05:42:02
Published:2020-09-07