Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Include holdfile in sql statement
Go
New
Search
Notify
Tools
Reply
  
[SOLVED] Include holdfile in sql statement
 Login/Join
 
Platinum Member
posted
Hi,

Is it possible to include a holdfile in a sql statement. (see example)

- first select values from CAR
- Print them to a holdfile
- use second select and use holdfile by
including it (I now it has to be a fex)
- finally print result

Simple example :

-* First selection
SQL
SELECT DISTINCT COUNTRY
FROM
( SELECT *
FROM CAR
WHERE COUNTRY IN ('ENGLAND', 'JAPAN', 'ITALY' )
)
;
TABLE ON TABLE HOLD AS H001
END

-* Make a holdfile with the IN values
TABLE FILE H001
PRINT COUNTRY AS ''
COMPUTE COMMA/A1 = IF COUNTRY EQ 'JAPAN' THEN '' ELSE ',';
ON TABLE SET PAGE-NUM NOLEAD
ON TABLE SET ASNAMES ON
ON TABLE HOLD AS INVALUES
ON TABLE NOTOTAL
END

-* New selection based on holdfile
SQL
SELECT COUNTRY, CAR
FROM
( SELECT *
FROM CAR
WHERE COUNTRY IN (
-INCLUDE INVALUES -*holdfile
)
)
;
TABLE ON TABLE HOLD AS H002
END

TABLE FILE H002
PRINT *
END

This message has been edited. Last edited by: <Kathryn Henning>,
 
Posts: 103 | Registered: March 18, 2008Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Hi Vincent!

Yes you can.
However, in your example you have 2 problems:
1. Your HOLD file should be in FORMAT ALPHA and should have the .fex extension.
2. You have to ensure that JAPAN is in fact the last value encountered

  
SQL
SELECT DISTINCT COUNTRY
FROM
( SELECT * 
 FROM CAR 
 WHERE COUNTRY IN ('ENGLAND', 'JAPAN', 'ITALY' ) 
)
;
TABLE ON TABLE HOLD AS H001
END

-* Make a holdfile with the IN values
FILEDEF INVALUES DISK INVALUES.FEX
TABLE FILE H001
PRINT 
 COMPUTE COMMA/A1 = IF COUNTRY EQ 'JAPAN' THEN '' ELSE ',';
BY COUNTRY
ON TABLE SAVE AS INVALUES
END

-* New selection based on holdfile
SQL
SELECT COUNTRY, CAR
FROM
( SELECT * 
 FROM CAR 
 WHERE COUNTRY IN (
-INCLUDE INVALUES 
 )
)
;
TABLE ON TABLE HOLD AS H002
END

TABLE FILE H002
PRINT *
END



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

 
Posts: 1940 | Location: Tel Aviv, Israel | Registered: March 23, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Unfortunately, there is an error in your code Danny and without quotes embracing the alpha values in a IN clause I don't know how it can work.

It may not be as elegant as it should, but it works:
SQL
SELECT DISTINCT COUNTRY
FROM
( SELECT * 
 FROM CAR 
 WHERE COUNTRY IN ('ENGLAND', 'JAPAN', 'ITALY') 
)
;
TABLE ON TABLE HOLD AS H001
END

-TYPE &LINES

-SET &INVALUES = '';
-SET &I = 0;
-REPEAT GENLST &LINES TIMES
-SET &I = &I + 1;
-READ H001 &VAL.&I.A10.
-TYPE &VAL.&I
-SET &INVALUES = &INVALUES || '''' || &VAL.&I || '''';
-SET &INVALUES = IF &I LT &LINES THEN &INVALUES || ',' ELSE &INVALUES;
-GENLST

-TYPE &INVALUES

SQL
SELECT COUNTRY, CAR
FROM
( SELECT * 
 FROM CAR 
 WHERE COUNTRY IN (
&INVALUES
 )
)
;
TABLE ON TABLE HOLD AS H002
END

TABLE FILE H002
PRINT *
END


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
 
Posts: 2269 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013Reply With QuoteReport This Post
Virtuoso
posted Hide Post
OOOPS!
Quite true.
Change this:
  
FILEDEF INVALUES DISK INVALUES.FEX
TABLE FILE H001
PRINT 
 COMPUTE COMMA/A1 = IF COUNTRY EQ 'JAPAN' THEN '' ELSE ',';
BY COUNTRY
ON TABLE SAVE AS INVALUES
END

To this:
  
FILEDEF INVALUES DISK INVALUES.FEX
TABLE FILE H001
PRINT 
 COMPUTE QCOUNTRY/A12='''' || COUNTRY || '''';
 COMPUTE COMMA/A1 = IF COUNTRY EQ 'JAPAN' THEN '' ELSE ',';
BY COUNTRY NOPRINT
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE SAVE AS INVALUES
END


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

 
Posts: 1940 | Location: Tel Aviv, Israel | Registered: March 23, 2006Reply With QuoteReport This Post
Platinum Member
posted Hide Post
Thanks guys, for all your help.
I got it working.

Kind regards

Mark
 
Posts: 103 | Registered: March 18, 2008Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Include holdfile in sql statement

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.