Hi,
I have the following SQL code in Access
This works well within a minute or so. However I'd like to make the where criteria (20180702-yyymmdd) come from a 'parameters' table I created, prmTable.Code:SELECT tb1.interest_key1 AS interest_key, tb1.Rate AS First_Mon_Rate, tb2.Rate AS Val_Rate FROM (SELECT left(interest_key,7) AS interest_key1, rate FROM SOURCETABLE WHERE INTEREST_KEY Like "*" & "220180702") AS tb1 LEFT JOIN (SELECT left(interest_key,7) AS interest_key1, rate FROM SOURCETABLEWHERE INTEREST_KEY Like "*" & "220180702") AS tb2 ON tb1.interest_key1 = tb2.interest_key1 ORDER BY tb1.interest_key1;
I updated the code as follows;
It now fails to run - I left it going over 20 mins and it crashes out.Code:SELECT tb1.interest_key1 AS interest_key, tb1.Rate AS First_Mon_Rate, tb2.Rate AS Val_Rate FROM (SELECT left(interest_key,7) AS interest_key1, rate FROM SOURCETABLE, prmTable WHERE INTEREST_KEY Like "*" & prmTable.[Mon_Date]) AS tb1 LEFT JOIN (SELECT left(interest_key,7) AS interest_key1, rate FROM SOURCETABLE, prmTable WHERE INTEREST_KEY Like "*" & "2" & prmTable.[Val_Date]) AS tb2 ON tb1.interest_key1 = tb2.interest_key1 ORDER BY tb1.interest_key1;
In my parameters table I have a field I called ID with a value of 1. I re-wrote my SQL to add a field with 1 in to a sub query and then join to the parameter table at the next step - this however also took ages (presumably because it first brings in all the prices.
Is there a smarter way of adding in a parameters table?
Frustratingly I also have a more basic query in the db that seems to work (runs in about 1:30);
I could split my original code above into two like this but it feels like it should be possible in one go.Code:SELECT Left(SOURCETABLE.interest_key,7) AS interest_key, SOURCETABLE.Rate AS First_Mon_Rate FROM SOURCETABLE, prmTable WHERE INTEREST_KEY Like "*" & "2" & prmTable.[Mon_Date] ORDER BY interest_key;
Note the SOURCETABLE is a linked table to an Oracle database which is quite large.
Grateful as ever for any help.
Many Thanks
Paul


Reply With Quote

