Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
flygstolen_fred
Creator
Creator

Lines fetched repeats

Hi,

I'm trying to concatenate to tables when certain conditions match (Category, Code, Countrycode and Dates in the Markup table).

Everything seems to work as it should in the app but the output in the load data-window says: InvoiceLines << Markup, Lines fetched, thousand times. The value also increase for every row in the output window. Am I missing something crucial?

Any help are appreciated.




The Order table contains approx 300 000 rows and the markup table contains about 150 rows. Is the nested for-loop the best solutions if I need to check multiple conditons (category, dates, code, country) before concatenation?


Order:

OrderIdCountryCodeRefererTotalOrderDate
1234SEGOOGLE3302016-01-05
1235NONEWSLETTER1052016-01-15

Invoice:

InvoiceIdOrderId
7891234
7901234
7911235

InvoiceLines:

InvoiceIdCodeDescrPriceCurrency
789CPCDescription 1150SEK
789CPODescription 2100SEK
790CPKDescription 380SEK
791CKJDescription 4105SEK

Markup:

CategoryCodeDescrCountryCodePriceFromDateToDate
GENERALALLText1 - internalSE172016-01-012016-01-01
GENERALALLText2 - internalNO152015-01-052015-12-31
REFERERGOOGLEFeeSE0.12015-05-012016-12-31

LET NumOfOrderRows = NoOfRows('Order');

LET NumOfMarkupRows = NoOfRows('Markup');

FOR i=0 to $(NumOfOrderRows)-1

  FOR j=0 to $(NumOfMarkupRows)-1

        IF (PEEK('CountryCode', $(j), 'Markup') = PEEK('CountryCode', $(i), 'Order') AND PEEK('Category', $(j), 'Markup') = 'REFERER' AND PEEK('Code', $(j), 'Markup') =PEEK('Referer',$(i), 'Order')) THEN

              LOAD

                  Applymap('OrderInvoiceKeyMap', PEEK('OrderId',$(i), 'Order')) as InvoiceId,

                  PEEK('Code', $(j), 'Markup') as Code,

                  PEEK('Descr', $(j), 'Markup') as Descr,

                  PEEK('Price', $(j), 'Markup') as Price,

                  IF (PEEK('CountryCode', $(i), 'Order') = 'SE', 'SEK',

                  IF (PEEK('CountryCode', $(i), 'Order') = 'DE', 'EUR', 'Unknown')) as Currency,

                  RESIDENT Markup;

        END IF

  NEXT j;

NEXT i;


(I use Applymap to get hold off the first InvoiceId for every Order)

10 Replies
flygstolen_fred
Creator
Creator
Author

Thanks swuehl, it works like a charm!

(Totally missed to reply to you when I got it working)