Focal Point
WebFOCUS and SQL

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

October 20, 2005, 01:10 PM
cyclonegigg
WebFOCUS and SQL
Hi there,

Can somebody tell me how to blend SQL and WebFOCUS together? For example, if I want to have my joins in SQL and proceed with the result of the join with WebFOCUS. Any configuration needed or you can just embed SQL with WebFOCUS?

Any ideas will be greatly appreciated.
October 20, 2005, 03:20 PM
newtofocus
You need to have the SQL PASSTHRU set to ON in the environment. Here is an example.

SET SQLENGINE = SQLMSS
SQL
SELECT ctc.c_last_name, count(isl.id) as total
FROM AHD.ctct ctc,
AHD.issalg isl,
AHD.issue iss
WHERE ctc.id=isl.analyst
AND isl.issue_id =iss.persid
AND isl.type = 'INIT'
AND isl.time_stamp > '1128211200'
AND iss.close_date > '1128211200'
AND iss.requestor IN
(SELECT id FROM AHD.ctct ctc
WHERE ctc.c_ctp_id = '2305')
Group by ctc.c_last_name
Order by total desc
FOR FETCH ONLY WITH UR;
TABLEF FILE SQLOUT
PRINT *
ON TABLE HOLD AS RGSQLOUT FORMAT ALPHA
END
TABLE FILE RGSQLOUT
PRINT *
WHERE READLIMIT EQ 100
END
October 20, 2005, 03:21 PM
newtofocus
You need to have the SQL PASSTHRU set to ON in the environment. Here is an example.

SET SQLENGINE = SQLMSS
SQL
SELECT ctc.c_last_name, count(isl.id) as total
FROM AHD.ctct ctc,
AHD.issalg isl,
AHD.issue iss
WHERE ctc.id=isl.analyst
AND isl.issue_id =iss.persid
AND isl.type = 'INIT'
AND isl.time_stamp > '1128211200'
AND iss.close_date > '1128211200'
AND iss.requestor IN
(SELECT id FROM AHD.ctct ctc
WHERE ctc.c_ctp_id = '2305')
Group by ctc.c_last_name
Order by total desc;
TABLEF FILE SQLOUT
PRINT *
ON TABLE HOLD AS RGSQLOUT FORMAT ALPHA
END
TABLE FILE RGSQLOUT
PRINT *
WHERE READLIMIT EQ 100
END
October 20, 2005, 03:47 PM
cyclonegigg
I had already tried that from looking at the old posts but I still couldnt get it to work. For example I get this error:
"(FOC012) THE WORD 'FILE' OR THE FILENAME APPEARS TWICE BYPASSING TO END OF COMMAND"

How do you set SQL PASSTHRU to ON?
Is there any way of knowing if your configuration is set to be used for SQL and WebFOCUS code?

Thanks!
October 20, 2005, 03:49 PM
cyclonegigg
And if it helps, this is my simple code of what I am trying to do:

SET SQLENGINE=SQLMSS

SQL SELECT LAST_NM, FIRST_NM
FROM NAMES1_TABLE
UNION ALL
SELECT LAST_NM, FIRST_NM
FROM NAMES2_TABLE
;

TABLE FILE SQLOUT
PRINT *
END
October 20, 2005, 04:12 PM
Woody
You probably need a Data Connection to the database and/or an ENGINE SQLMSS statement.

ENGINE SQLMSS SET SERVER &DataConnection
SET SQLENGINE = SQLMSS
ENGINE SQLMSS
SELECT *
FROM tablename;
TABLE FILE SQLOUT
PRINT *
IF READLIMIT EQ 5
END
October 20, 2005, 04:19 PM
Noreen Redden
You can actually do that in FOCUS without worrying about SQL. If you want just 2 columns, one with last name (from both tables and one with first from both tables,
TABLE FILE NAMES1_TABLE
October 20, 2005, 04:24 PM
Noreen Redden
Sorry, I tried cut-and-paste and it sent the message before I was done.
TABLE FILE NAMES1_TABLE
PRINT LAST_NM FIRST_NM
MORE
FILE NAMES2_TABLE
END

This should give you what you want. If you want 4 columns, merged on a common key (such as SSN, then look at MATCH FILE
October 20, 2005, 04:34 PM
cyclonegigg
Woddy,
what would Data Connection represent? server name? Is it the same as declaring connection attributes?

PS: Thanks Noreen for the suggestion but I am working with many and that was just an example.
October 21, 2005, 12:50 PM
Woody
A Data Connection is just what it indicates - a connection to the database. WebFocus doesn't know which database you wish to use unless you (or your WebFocus Administrator) creates a Data Connection. As a simple test - if you can query any table in a given database with WebFocus then you already have a connection. If you cannot access any tables via WebFocus then you probably need a Data Connection. Speak with your WebFocus Administrator.

The member "newtofocus" demonstrates the WebFocus SQL Passthru syntax more elaborately that my previous post. The query also demonstrates SQL Joins. What you may (and I emphasize the word "may") be missing is either a Data Connection or the ENGINE SQLMSS statement. (See my previous post.) The ENGINE SQLMSS statement isn't always needed, but I have found that it sometimes makes the difference.

Regarding Noreen's suggestion, both MORE and MATCH will combine several result sets together. MORE requires the each result set to have the same file structure whereas MATCH requires each result set to have the same BY field.

If these suggestions don't achieve the desired result, please elaborate on your requirement.
October 21, 2005, 01:29 PM
cyclonegigg
Thank you much Woody, Noreen, and newtofocus!
It's working nowSmiler

PS:
I know how to use MORE and MATCH but with the code that I am working on, it is very inefficient using either of them.