Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED]SQL "NOT EXISTS" Equivalent in WebFOCUS

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[CLOSED]SQL "NOT EXISTS" Equivalent in WebFOCUS
 Login/Join
 
Silver Member
posted
Hello,

I am new to WebFOCUS, so excuse any rookie comments and questions.

I am fairly fluent in sql and wondering how I could do a subquery that would consist a NOT EXISTS operator.

I have 2 tables and I need to remove values from table #1(correlated subquery) that are contained in table #2(subquery). So, if I created a query it would look like this...

DECLARE
@startDate DATE,
@endDate DATE

SELECT DISTINCT
customerNumber
FROM
customer
WHERE NOT EXISTS
(
SELECT DISTINCT
customerNumber
FROM
customerOrders
WHERE
orderDate >= @startDate
AND orderDate <= @endDate
);

The result would be a dataset that contains all customer numbers that DID NOT order during the date period that was entered.
Please help! Easiest method to do this would be appreciated, along with dummy instructions.

Thanks!

This message has been edited. Last edited by: <Emily McAllister>,
 
Posts: 47 | Registered: February 02, 2016Report This Post
Virtuoso
posted Hide Post
Look into the CONTAINS and OMITS operators...


8.2.02M (production), 8.2.02M (test), Windows 10, all outputs.
 
Posts: 1113 | Location: USA | Registered: January 27, 2015Report This Post
Virtuoso
posted Hide Post
TABLE FILE CAR
PRINT COUNTRY
WHERE COUNTRY EQ 'ENGLAND';
ON TABLE HOLD FORMAT ALPHA
END
TABLE FILE CAR
SUM RCOST 
BY COUNTRY
WHERE COUNTRY NE (HOLD);
END


WebFOCUS 8206, Unix, Windows
 
Posts: 1853 | Location: New York City | Registered: December 30, 2015Report This Post
Silver Member
posted Hide Post
BabakNYC, your method works. The issue is when choose a date range outside of a few days, the system locks out. Is their a more efficient way to do this?


WebFOCUS 8
Windows, All Outputs
 
Posts: 47 | Registered: February 02, 2016Report This Post
Virtuoso
posted Hide Post
Maybe you could join CUSTOMER to CUSTOMERORDERS and using the same WHERE, you'll get there.

Alternatively, you could just use the SQL and paint a report against the answer set of the SQL.

Look up DB_EXPR function in the documentation for use cases. Syntax is pretty easy and if you're more comfortable with SQL it might be the way to go.


WebFOCUS 8206, Unix, Windows
 
Posts: 1853 | Location: New York City | Registered: December 30, 2015Report This Post
Expert
posted Hide Post
Look into the SQL_SCRIPT functionality, available in WF 7.7.05 and newer.

quote:
Reference: FORMAT SQL_SCRIPT
Description: Creates an SQL subquery file or a file of data values with a corresponding synonym.

When used in a request against a relational data source, the HOLD FORMAT SQL_SCRIPT command generates the SQL SELECT statement needed to execute the current query. It then stores it in the application folder as a file with a .sql extension, along with the Master and Access File pair that describes the SQL answer set.

When used in a request against any other type of data source, the HOLD FORMAT SQL_SCRIPT command executes the current query and stores the retrieved values in the application folder as a sequential file with a .ftm extension, along with the Master File that describes the retrieved data.

Use: You can use the output from HOLD FORMAT SQL_SCRIPT as the target file for the DB_INFILE function. For information about the DB_INFILE function, see the Using Functions manual


You first create a HOLD file that will contain the SQL for the sub-select, then you use the HOLD file as a filter in the main request. Something like this - Syntax not verified:

TABLE FILE customerOrders
PRINT DST.customerNumber
WHERE
orderDate GE '&startDate'
AND orderDate LE '&endDate'
ON TABLE HOLD AS HSUBSEL1 FORMAT SQL_SCRIPT
END
-RUN

TABLE FILE customer
PRINT DST.customerNumber

WHERE NOT DB_INFILE (HSUBSEL1, customerNumber, customerNumber)
END
-RUN


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Expert
posted Hide Post
The HOLD FORMAT SQL_SCRIPT does not retrieve data - it creates a SQL select statement.

The DB_INFILE function uses the SQL_SCRIPT statement to generate the subselect. If you turn SQL traces on, you will see the generated SQL.

This is a working example that uses an IBI supplied RDBMS table:

-SET &ECHO=ALL;
SET MSG=ON
SET TRACEOFF = ALL
SET TRACEON = SQLTRANS
SET TRACEON = STMTRACE//CLIENT
SET TRACEON = SQLAGGR//CLIENT
SET TRACESTAMP = OFF
SET TRACEWRAP = 78
SET TRACEUSER = ON
-RUN

TABLE FILE WFR80_WRD_DIM_CUSTOMER
PRINT
GENDER
WHERE GENDER EQ 'Female'

ON TABLE HOLD AS BASEAPP/SQL_FEMALE2 FORMAT SQL_SCRIPT
END
-RUN

TABLE FILE WFR80_WRD_DIM_CUSTOMER
SUM
LAST_NAME
BY LAST_NAME NOPRINT

WHERE DB_INFILE(SQL_FEMALE2, GENDER, GENDER)

HEADING
"Female Customers"

ON TABLE HOLD
END
-RUN


SELECT
T1."Last_Name",
MAX(T1."Last_Name")
FROM
WF_REPOS.WRD_DIM_CUSTOMER T1
WHERE
(T1."Gender" IN 
( 
    SELECT
    (T1."Gender") AS E01
    FROM
    WF_REPOS.WRD_DIM_CUSTOMER T1
    WHERE
    (T1."Gender" = 'Female'))
)
GROUP BY
T1."Last_Name"
ORDER BY
T1."Last_Name";

This message has been edited. Last edited by: Francis Mariani,


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
You could also accomplish this with direct pass-thru SQL:

SET SQLENGINE = SQLMSS (or SQLORA, etc.)

SQL

DECLARE 
 @startDate DATE,
 @endDate DATE

SELECT DISTINCT
 customerNumber
FROM
 customer
WHERE NOT EXISTS
 (
 SELECT DISTINCT
 customerNumber
 FROM
 customerOrders
 WHERE
 orderDate >= @startDate
 AND orderDate <= @endDate
 );

TABLE
 ON TABLE HOLD AS xxxx
END



WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Silver Member
posted Hide Post
I am running into an issue according to the trace. It looks to be the last WHERE clause. Which table with customerNumber is supposed to go first in the WHERE DB_INFILE? Is it WHERE DB_INFILE (HSUBSEL1, customerOrders.customerNumber, customer.customerNumber)? Or vice-versa? Thanks for all your help.


WebFOCUS 8
Windows, All Outputs
 
Posts: 47 | Registered: February 02, 2016Report This Post
Silver Member
posted Hide Post
This is the error I am always getting...


SET MSG=ON
SET TRACEOFF = ALL
SET TRACEON = SQLTRANS
SET TRACEON = STMTRACE//CLIENT
SET TRACEON = SQLAGGR//CLIENT
SET TRACESTAMP = OFF
SET TRACEWRAP = 78
SET TRACEUSER = ON
TABLE FILE PE_HHHORDHP
PRINT
PE_HHHORDHP.PE_HHHORDHP.HHHCUSN
WHERE PE_HHHORDHP.PE_HHHORDHP.HHHARCD EQ 'A';
WHERE HHHCMPN EQ ' 1';
WHERE HHHDIVN EQ ' 1';
WHERE HHHDPTN EQ ' 1';
WHERE PE_HHHORDHP.PE_HHHORDHP.HHHDTET GE 20160101;
WHERE PE_HHHORDHP.PE_HHHORDHP.HHHDTET LE 20160101;
ON TABLE HOLD AS SUBSET1 FORMAT SQL_SCRIPT
END
TABLE FILE PE_ZHESUMHP
PRINT
PE_ZHESUMHP.PE_ZZFCSTPP.ZZFCUSF
WHERE ZZFARCD EQ 'A';
WHERE ZZFCMPN EQ ' 1';
WHERE ZZFDIVN EQ ' 1';
WHERE ZZFDPTN EQ ' 1';
WHERE ZZFDTEI GE '20150101';
WHERE NOT DB_INFILE(SUBSET1, HHHCUSN, HHHCUSN);
END
SELECT
(T1."HHHCUSN") AS "E01"
FROM
PWRDTA.HHHORDHP T1
WHERE
(T1."HHHDTET" <= 20160101) AND
(T1."HHHDTET" >= 20160101) AND
(T1."HHHDPTN" = ' 1') AND
(T1."HHHDIVN" = ' 1') AND
(T1."HHHCMPN" = ' 1') AND
(T1."HHHARCD" = 'A');
FOC2546 - SQL SCRIPT SUBSET1.SQL CREATED SUCCESSFULLY (BUT NOT EXECUTED)
0 ERROR AT OR NEAR LINE 31 IN PROCEDURE ADHOCRQ FOCEXEC *
(FOC258) FIELDNAME OR COMPUTATIONAL ELEMENT NOT RECOGNIZED: HHHCUSN
BYPASSING TO END OF COMMAND
(FOC009) INCOMPLETE REQUEST STATEMENT


WebFOCUS 8
Windows, All Outputs
 
Posts: 47 | Registered: February 02, 2016Report This Post
Virtuoso
posted Hide Post
Does it still error out if you change it to:

WHERE NOT DB_INFILE(SUBSET1, E01, E01);


WebFOCUS 8206, Unix, Windows
 
Posts: 1853 | Location: New York City | Registered: December 30, 2015Report This Post
Silver Member
posted Hide Post
Yes, it does. Same error code. If I try your method, it works to a degree, but I get this error, which its the server timing out due to a cursor...


0 NUMBER OF RECORDS IN TABLE= 22480 LINES= 22480
(FOC1400) SQLCODE IS -101 (HEX: FFFFFF9B)
: [54001] [IBM][CLI Driver][AS] SQL0101N The statement was not processed
: because a limit such as a memory limit, an SQL limit, or a database limi
: t was reached. SQLSTATE=54001
L (FOC1406) SQL OPEN CURSOR ERROR. : PE_ZZFCSTPP


WebFOCUS 8
Windows, All Outputs
 
Posts: 47 | Registered: February 02, 2016Report This Post
Virtuoso
posted Hide Post
Did you ever try Joining the two tables? That might still be a viable solution. Doesn't hurt to try.


WebFOCUS 8206, Unix, Windows
 
Posts: 1853 | Location: New York City | Registered: December 30, 2015Report This Post
Virtuoso
posted Hide Post
You can obtain the results of a WHERE NOT EXISTS by using a conditional LEFT JOIN.

A few notes:

  • Make sure that you SET SHORTPATH = SQL, or NULLs will be omitted from the results, preventing you from filtering out the left join set.
  • Put your NOT EXISTS condition in the JOIN conditions, not in the WHERE clause of the TABLE request, or WF will turn your join into an INNER join.
  • Make sure that your left join does not return multiple rows for a single row in your source table, or you'll end up with duplicate results.
  • Finally, exclude the LEFT JOIN results using WHERE {SOME_LEFT_JOINED_FIELD} IS MISSING;


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1669 | Location: Enschede, Netherlands | Registered: August 12, 2010Report This Post
Virtuoso
posted Hide Post
Try this (the SET ALL=PASS may have no effect):

SET SHORTPATH = SQL
SET ALL       = PASS
-*
JOIN CLEAR *
JOIN CUSTOMERNUMBER IN CUSTOMER TO ALL CUSTOMERNUMBER IN CUSTOMERORDERS AS J1
-*
DEFINE FILE CUSTOMER
 EXCLUDE_CUSTOMER/A1 MISSING ON = IF (CUSTOMERORDERS.CUSTOMERNUMBER IS MISSING) THEN MISSING ELSE
                                  IF (CUSTOMERORDERS.ORDERDATE FROM '&STARTDATE' TO '&ENDDATE') THEN 'Y' ELSE 'N';
END
-*
TABLE FILE CUSTOMER
 BY CUSTOMER.CUSTOMERNUMBER
 WHERE (EXCLUDE_CUSTOMER IS MISSING)
    OR (EXCLUDE_CUSTOMER EQ 'N');
END


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Expert
posted Hide Post
Did you manually modify the metadata (master) for the two tables AFTER you generated them?


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Platinum Member
posted Hide Post
RMM -

I deal with this sort of situation fairly often. My recommendation is to use either SQL Direct Passthru (DPT) or Automatic Passthru (APT).

These techniques are all very well documented.
 
Posts: 164 | Registered: March 26, 2003Report This Post
Expert
posted Hide Post
quote:
SQL Direct Passthru (DPT) or Automatic Passthru (APT)

Interesting, I've never heard of these terms or acronyms...


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED]SQL "NOT EXISTS" Equivalent in WebFOCUS

Copyright © 1996-2020 Information Builders