|
||||||||||||
Focal Point Forums
WebFOCUS/FOCUS Forum on Focal Point
[SOLVED] Table File Join within SQL SQLDBC queryGo ![]() | New ![]() | Search ![]() | Notify ![]() | Tools ![]() | Reply ![]() | |
| Member |
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.1 | ||
|
| Platinum Member |
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 | |||
|
| Virtuoso |
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 | |||
|
| Member |
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.1 | |||
|
| Member |
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.1 | |||
|
| Platinum Member |
Thanks Danny It works . 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 | |||
|
| Member |
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.1 | |||
|
| Expert |
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
| |||||||||
|
| Virtuoso |
Tony, Nice (as usual)... Tim, I see your problem. It is here:
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 | |||
|
| Expert |
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 Seasons greetings to you and the team in Israel T
| |||||||||
|
| Powered by Social Strata |
| Please Wait. Your request is being processed... |
|
Focal Point Forums
WebFOCUS/FOCUS Forum on Focal Point
[SOLVED] Table File Join within SQL SQLDBC query
