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     how to use sql in focus????
Go
New
Search
Notify
Tools
Reply
  
how to use sql in focus????
 Login/Join
 
<beginner>
posted
Dear all;

I try to do the following:

there exist 2 tables in database

TABLE 1:
STUDENT GROUP PHONE_NO
A 1 333-4567
B 2 333-4578
C 1 333-4589

TABLE 2:
STUDENT GROUP MOBILE_NO
A 1 999-8888
B 2 999-6541
C 1 999-7777

using FOCUS
I'd like to show the following in the report:

STUDENT MOBILE
A 999-8888
B 999-7777

I wrote down :

SET SQLENGINE=SQLORA
SQL PREPARE FOR TEMPTABLE
SELECT A.STUDENT,
DECODE(A.GROUP,1,B.MOBILE_NO,A.PHONE_NO)
FROM TABLE1 A, TABLE2 B
WHERE A.STUDENT=B.STUDENT AND
A.GROUP=B.GROUP
END
-RUN

TABLE FILE TEMPTABLE
PRINT *
END
-RUN

It didn't print anything in the report. Am I missing anything or is it the right way to do it?

Please help ASAP,

new focuser
 
Reply With QuoteReport This Post
<Grzegorz>
posted
If you would like to use prepared SQL statement you can use the following syntax (I changed GROUP column name to GROUP_ID because my Oracle RDBMS does not like GROUP as a column name):

SET SQLENGINE=SQLORA
-*
SQL PREPARE STUDENT_QUERY FROM
SELECT A.STUDENT,
DECODE(A.GROUP_ID,1,B.MOBILE_NO,A.PHONE_NO) MOBILE
FROM TABLE1 A, TABLE2 B
WHERE A.STUDENT=B.STUDENT AND
A.GROUP_ID=B.GROUP_ID
END
-*
SQL EXECUTE STUDENT_QUERY;
TABLE
ON TABLE HOLD
END
-RUN
TABLE FILE HOLD
PRINT *
END
If you do not want to use prepared statement, there is even simpler syntax:

SQL SQLORA
SELECT A.STUDENT,
DECODE(A.GROUP_ID,1,B.MOBILE_NO,A.PHONE_NO) MOBILE
FROM TABLE1 A, TABLE2 B
WHERE A.STUDENT=B.STUDENT AND
A.GROUP_ID=B.GROUP_ID;
END
or

SQL SQLORA
SELECT A.STUDENT,
DECODE(A.GROUP_ID,1,B.MOBILE_NO,A.PHONE_NO) MOBILE
FROM TABLE1 A, TABLE2 B
WHERE A.STUDENT=B.STUDENT AND
A.GROUP_ID=B.GROUP_ID;
TABLE
ON TABLE HOLD
END
TABLE FILE HOLD
-* Use the FOCUS syntax, here:
-* ...
ENDThe "FOCUS-SQL" syntax is described and explained within the manual: "IWay SQL Reference Version 5 Release 2.0".

Hope this helps
Grzegorz

This message has been edited. Last edited by: <Mabel>,
 
Reply With QuoteReport This Post
<beginner>
posted
Thank you very much for you help.
I have further questions.
What if I want the following:

STUDENT GROUP NUMBER
A 1 999-8888
B 2 333-4578
C 1 999-7777

note: if group = 1, show mobile number
if group = 2, shoue phone number

Please help me Frowner
 
Reply With QuoteReport This Post
<Grzegorz>
posted
The following query is just doing it (using Oracle syntax):

SQL SQLORA
SELECT A.STUDENT, A.GROUP_ID,
DECODE(A.GROUP_ID,
1, B.MOBILE_NO,
2, A.PHONE_NO) PH_NUMBER
FROM TABLE1 A, TABLE2 B
WHERE A.STUDENT=B.STUDENT AND
A.GROUP_ID=B.GROUP_ID;
END
The equivalent syntax in FOCUS is (at least one of the possibilities):

SQL SQLORA
SELECT A.STUDENT, A.GROUP_ID,
B.MOBILE_NO, A.PHONE_NO
FROM TABLE1 A, TABLE2 B
WHERE A.STUDENT=B.STUDENT AND
A.GROUP_ID=B.GROUP_ID;
TABLE
ON TABLE HOLD AS STUDENTS
END
-*
DEFINE FILE STUDENTS
NUMBER/A9 = IF GROUP_ID EQ '1' THEN MOBILE_NO
ELSE PHONE_NO;
END
-*
TABLE FILE STUDENTS
PRINT NUMBER
BY STUDENT
BY GROUP_ID AS 'GROUP'
END
You can, of course, create WF synonym with joined TABLE1 and TABLE2, and the Oracle query will be generated "in the background".

Hope this helps
Grzegorz

This message has been edited. Last edited by: <Mabel>,
 
Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     how to use sql in focus????

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