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     [SOLVED] UNIONS in SQL passthru giving errors

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] UNIONS in SQL passthru giving errors
 Login/Join
 
Member
posted
I am trying to run a query via SQL passthru and the SQL code contains a union join. The data does not get parsed in WebFocus but when I run it manually in my SQL browser it works as expected. I think it is to do with the brackets in the select statement but the brackets are necessary for the query to be valid. Is there any other code that I need to place for this to work?

  
SET EMPTYREPORT=ON
ENGINE SQLMYSQL SET DEFAULT_CONNECTION t2
ENGINE SQLMYSQL SET VARCHAR OFF
SQL SQLMYSQL PREPARE SQLOUT FOR

(SELECT LS.NAME,
         CASE
             WHEN (LA.Status='C') THEN 'U'
             WHEN (LA.Status='A') THEN 'A'
             ELSE 'N/A'
         END AS "Account_Status",
         Count("Account_Status") AS 'Counts'
  FROM account LA LEFT JOIN scheme LS ON (LA.scheme_id = LS.scheme_id)
  WHERE LS.scheme_id IN (1,2,3)
  GROUP BY "Account_Status",LS.scheme_id
  ORDER BY LS.scheme_id,"Account_Status")
UNION 
(SELECT LS.NAME,
         CASE
             WHEN (LA.Status='C') THEN 'U'
             ELSE 'N/A'
         END AS "Account_Status",
         Count("Account_Status") AS 'Counts'
  FROM account LA LEFT JOIN scheme LS ON (LA.scheme_id = LS.scheme_id)
  WHERE LS.loyalty_scheme_id IN (4,5,6)  
  GROUP BY "Account_Status",LS.scheme_id  
  ORDER BY LS.scheme_id,"Account_Status")
 
END
 
-RUN

TABLE FILE SQLOUT
PRINT *
ON TABLE PCHOLD FORMAT DFIX DELIMITER , HEADER YES ENCLOSURE "
END



When I run this I get the following error
 
(FOC1400) SQLCODE IS -1 (HEX: FFFFFFFF) XOPEN: 00000
 :  (-1) [00000] JDBFOC>> describecols():  error: getMetaData call on stmt
 : returned null ResultSetMetaData object!
 L    (FOC1405) SQL PREPARE ERROR.
 0 ERROR AT OR NEAR LINE     35  IN PROCEDURE _sql_custom
 (FOC205) THE DESCRIPTION CANNOT BE FOUND FOR FILE NAMED: SQLOUT
 BYPASSING TO END OF COMMAND 

This message has been edited. Last edited by: touch,


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 17 | Registered: April 13, 2012Report This Post
Platinum Member
posted Hide Post
I very rarely use SQL Passthoughs but I believe your SQL statement has to be terminated with a semi-colon before the END statement.


WF 7.7.04, WF 8.0.7, Win7, Win8, Linux, UNIX, Excel, PDF
 
Posts: 175 | Location: Pomona, NY | Registered: August 06, 2003Report This Post
Member
posted Hide Post
Not sure this is 100% - but should get you closer. Good luck and hope this helps!
/*
Some SQL requirements:
1. no double quotes (unless you've set that to be the default)
2. you must do a 'group by' on all selected (non-aggregate) fields when using an aggregate ('count' in this case)
3. in a Union, the 'Order by' can only be in the last Select statement
4. In your last Select (above), why group on a field (loyalty_scheme_id) that hasn't been selected? (I added it to the select)
*/

SELECT ls.acct_name 'Account Name' ,
CASE la.acct_status
WHEN 'C' THEN 'U'
WHEN 'A' THEN 'A'
ELSE 'N/A'
END AS Account_Status ,
ls.loyalty_scheme_id 'Scheme ID',
COUNT(la.acct_status) AS Counts
FROM loyalty_scheme ls
LEFT JOIN loyalty_account la ON ls.loyalty_scheme_id = la.loyalty_scheme_id
WHERE ls.loyalty_scheme_id IN ( 1, 2, 3 )
GROUP BY ls.acct_name ,
la.acct_status,
ls.loyalty_scheme_id
UNION
SELECT ls.acct_name 'Account Name',
CASE la.acct_status
WHEN 'C' THEN 'U'
ELSE 'N/A'
END AS Account_Status ,
ls.loyalty_scheme_id 'Scheme ID',
COUNT(la.acct_status) AS Counts
FROM loyalty_account la
LEFT JOIN loyalty_scheme ls ON ls.loyalty_scheme_id = la.loyalty_scheme_id
WHERE ls.loyalty_scheme_id IN ( 4, 5, 6 )
GROUP BY ls.acct_name ,
la.acct_status,
ls.loyalty_scheme_id
ORDER BY ls.acct_name
 
Posts: 22 | Location: Tulsa, OK | Registered: February 17, 2011Report This Post
Member
posted Hide Post
Forgot to mention that you should 'test drive' your SQL in SSMS first...
 
Posts: 22 | Location: Tulsa, OK | Registered: February 17, 2011Report This Post
Gold member
posted Hide Post
Try putting your CASE statements all on one line - I've found that the "END" keyword on a CASE statement will break my SQL passthrough if its on a separate line from the CASE.

CASE WHEN (LA.Status='C') THEN 'U' WHEN (LA.Status='A') THEN 'A' ELSE 'N/A' END AS "Account_Status",


- I use passthrough with Oracle SQL, and have used UNIONs successfully. In fact, I can't say that I've found a valid SELECT statement that I can't run as passthrough yet (and I've run some exotic ones!) . . .

Rob


WebFocus 8201m on Windows; App Studio 8201; Procedures: WebFocus with SQL; HTML Parameter Pages & Dashboard; Output: Excel, HTML, & PDF.
 
Posts: 88 | Location: MI | Registered: July 23, 2009Report This Post
Member
posted Hide Post
I have tried playing around with it and it seems to be working!

Thanks a lot to JALdbaDEV and MathematicalRob

Hopefully, this will make it easier for our team to build more complex reports


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 17 | Registered: April 13, 2012Report 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     [SOLVED] UNIONS in SQL passthru giving errors

Copyright © 1996-2020 Information Builders