Focal Point
[SOLVED] Table File Join within SQL SQLDBC query

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8387006886

December 10, 2017, 12:41 PM
Tim A
[SOLVED] Table File Join within SQL SQLDBC query
Does anyone have an example or explanations on how to join a WF Table File within an SQLDBC query?

I built a WF table file (CARLIST) holding a list of cars that I would like to use to limit the number of records brought back while running an SQL query against our railcar DW table (CARMOVES) with millions of records. Here is an example of what I have tried so far, but due to the number of car records in the CARMOVES table - this times out.

SQL SQLDBC

SELECT car, waybill, nettons

FROM dw database.car_movement_table A

WHERE A.CAR IN FILE CARLIST
;
TABLEF FILE SQLOUT
ON TABLE HOLD AS X
TABLE FILE X
PRINT *

This message has been edited. Last edited by: FP Mod Chuck,


WF 8.2
December 11, 2017, 01:29 AM
Chaudhary
Tim,

instead of creating a hold file , you can directly join your tables in sql Passthrough ,

OR if you have limited records in hold file catlist you can read the records and assign those records to a variable using loop . and then pass that variable in where statement .

Try This code,
 -DEFAULTH &CAR_UNIT = '';
-SET &CAR_FILTER = '';
-SET &ECHO = ALL;
-RUN
TABLE FILE CAR
BY CAR AS 'CAR_UNIT'
ON TABLE SET ASNAMES ON
ON TABLE HOLD AS CAR_LIST
END
-RUN
-SET &CAR_FILTER = '(';
-REPEAT :FILTERCAR &LINES TIMES
-READFILE CAR_LIST
-SET &UNITLEN = ARGLEN(&CAR_UNIT.LENGTH,&CAR_UNIT,'I2') ;
-SET &CARUNIT= TRIM('T',&CAR_UNIT, &CAR_UNIT.LENGTH, ' ', 1, 'A&UNITLEN.EVAL');
-SET &CAR_FILTER = &CAR_FILTER ||''''||&CARUNIT||''',';
-:FILTERCAR
-SET &CAR_FILTER = SUBSTR(&CAR_FILTER.LENGTH, &CAR_FILTER.QUOTEDSTRING, 1, &CAR_FILTER.LENGTH - 2 , &CAR_FILTER.LENGTH - 2, 'A&CAR_FILTER.LENGTH') || ''')';


SQL SQLDBC

SELECT car, waybill, nettons

FROM dw database.car_movement_table A

WHERE A.CAR IN &CAR_FILTER; 



Run time code will become like ,

 SQL SQLDBC
 SELECT car, waybill, nettons
 FROM dw database.car_movement_table A
 WHERE A.CAR IN ('ALFA ROMEO','AUDI','BMW','DATSUN','JAGUAR','JENSEN','MASERATI','PEUGEOT','TOYOTA','TRIUMPH')  ;
 



WF Production :- WF:8.0.0.4, 8.1.05 App-studio/Developer Studio(8.1.x) ,
8.2.0.1M , 8.2.0.2 (App-Studio8.2.x),
InfoAssist/+, InfoDiscovery
Output format:-AHTML, PDF, Excel, HTML
Platform:-Windows 7, 8,10
December 11, 2017, 10:07 AM
Danny-SRL
Chaudhary,
Another way, without a loop:
  
DEFINE FILE CAR
QCAR/A20='''' || CAR || ''',';
END
TABLE FILE CAR
SUM CNT.CAR
SUM QCAR
ACROSS CAR
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE SAVE AS CAR_LIST
END
-RUN
-READ CAR_LIST &CLEN.A5 
-RUN
-SET &LEN=&CLEN * 20;
-READ CAR_LIST &CLEN.A5. &CARLIST.A&LEN.EVAL.
-SET &CARLIST=TRIM('T', RJUST(200, &CARLIST, 'A200'), 200, ',', 1, 'A200');
-TYPE &CARLIST

&CARLIST contains:
  
'ALFA ROMEO',       'AUDI',             'BMW',              'DATSUN',           'JAGUAR',           'JENSEN',           'MASERATI',         'PEUGEOT',          'TOYOTA',           'TRIUMPH'



Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

December 11, 2017, 12:17 PM
Tim A
Thank you very much, I used variable loop logic and this did the trick. Good thinking - I will also check out the second method without loop. Much appreciated!


WF 8.2
December 11, 2017, 12:21 PM
Tim A
David thanks for the response as well. Three good options here that I will make sure to keep in mind in the future. thanks


WF 8.2
December 12, 2017, 01:05 AM
Chaudhary
quote:
Chaudhary,
Another way, without a loop:


Thanks Danny It works . Good One


WF Production :- WF:8.0.0.4, 8.1.05 App-studio/Developer Studio(8.1.x) ,
8.2.0.1M , 8.2.0.2 (App-Studio8.2.x),
InfoAssist/+, InfoDiscovery
Output format:-AHTML, PDF, Excel, HTML
Platform:-Windows 7, 8,10
December 12, 2017, 09:19 AM
Tim A
I tried the 'without a loop' code this morning and am having some issues. So, there are only 21 cars in the car table (MT)this morning and the code is failing on the -READ CAR_LIST &CLEN.A5 line


this runs through the table file hold across cars just fine and fails for 'unrecocgnized format of amper variable -READ CAR_LIST &CLEN.A5 &CARLIST.A&LEN.EVAL.

MT is the file holding the car list, and the car field is A14.

DEFINE FILE MT
QCAR/A20='''' || CAR || ''',';
END

TABLE FILE MT
SUM CNT.CAR
SUM QCAR
ACROSS CAR
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE SAVE AS CAR_LIST
END


-RUN
-READ CAR_LIST &CLEN.A5
-RUN
-SET &LEN=&CLEN * 20;
-READ CAR_LIST &CLEN.A5. &CARLIST.A&LEN.EVAL.
-SET &CARLIST=TRIM('T', RJUST(200, &CARLIST, 'A200'), 200, ',', 1, 'A200');
-TYPE &CARLIST


WF 8.2
December 12, 2017, 10:51 AM
Tony A
A slightly more compact no-loop method by relying upon the Title values within a COMT file (comma delimited with titles).

Because this only reads the first line, removes spaces and truncates the result, we can set the length of read to be ([length of CAR field + 2] * number of output records) - 1 and not have to bother with getting the count from within the table request.

-DEFAULTH &CARLIST = ''
TABLE FILE CAR
SUM COMPUTE BLNK/A1 = ''; AS ''
ACROSS CAR
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE SAVE AS CAR_LIST FORMAT COMT
END
-RUN
-SET &LEN=(&RECORDS * 22)-1;
-READ CAR_LIST &CARLIST.A&LEN.EVAL.

-SET &CARLIST=STRREP(&CARLIST.LENGTH, &CARLIST.QUOTEDSTRING, 1, ' ', 0, 'x',  &CARLIST.LENGTH, 'A&CARLIST.LENGTH');
-SET &CARLIST=TRUNCATE(&CARLIST);
-TYPE &CARLIST


T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
December 12, 2017, 02:00 PM
Danny-SRL
Tony,
Nice (as usual)...

Tim,
I see your problem. It is here:
quote:

-SET &CARLIST=TRIM('T', RJUST(200, &CARLIST, 'A200'), 200, ',', 1, 'A200');


My mistake. It should read:
  
-SET &CARLIST=TRIM('T', RJUST(&CLEN, &CARLIST, 'A&CLEN.EVAL'), &CLEN, ',', 1, 'A&CLEN.EVAL');



Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

December 13, 2017, 03:08 AM
Tony A
Thanks Danny,

I tried to use SUM CAR ACROSS CAR and then grab the second line in the output COMT or the first line in a COM (as it would already be the exact variable this needs) but didn't give too much effort into it Wink

Seasons greetings to you and the team in Israel

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10