August 01, 2005, 04:09 PMwebfocusdev
Using dialog manager in sql passthru
Is it possible to use dialog manager in a sql passthru to build a dynamic select statement without breaking the sql. I need to test the value of an amper variable and modify the select statement based on its value. If so, does anyone have an example?
August 01, 2005, 05:58 PMj.gross
Bear in mind that the fex is executed in two stages:
In stage 1, Dialog Manager (which does not understand Focus syntax) performs all the DM directives (-if, -set, -repeat etc.); and performs substitution of DM &vars imbedded in the Focus lines, and stacks them for execution in stage 2. Stage 1 ends at end of the fex, or when -RUN, or -EXIT is encountered.
In stage 2, Focus executes the stacked lines.
So you can insert DM statements between and around your lines of SQL and TABLE code, and perhaps imbed DM variables (amper vars) in the SQL code itself.
Add -RUN after the END statement if you want to resume DM processing after the data retrieval is complete, e.g., to test &LINES), and there you are.
Just make sure that the SQL (and TABLE) code generated will be valid, for all possible combinations of conditions (amper parameters).
For example, to screen on one or more columns, depending on input parameters, I have used code like this:
-IF &ALPHA EQ ' ' GOTO ALPHA.X;
&WHERE (ALPHA = '&ALPHA')
-IF &BETA EQ ' ' GOTO BETA.X;
&WHERE (BETA = '&BETA')
-IF &GAMMA EQ ' ' GOTO GAMMA.X;
&WHERE (GAMMA= '&GAMMA)
. . .
This ensures that the first clause of the WHERE condition that the fex generates will start with WHERE, and all subsequent ones with OR.
August 01, 2005, 07:31 PMwebfocusdev
Thanks Jack...I'll give that a try. Until your response, I was trying to do something like this. This is just a test query but it works...
-SET &SQLTEST = IF &DATETYPE EQ 'Bar Date' THEN ',a.assignment_id FROM PAL.SD sd, PAL.SD_ASSIGNMENT a WHERE a.sd_number = sd.sd_number;'<br />-ELSE 'FROM PAL.SD sd;';<br /><br /><br />SET SQLENGINE=SQLORA<br />SQL SET SERVER &MYSERV<br />SQL SELECT sd.sd_number,<br /> sd.doe_s_number<br /> &SQLTEST<br />END
However, it breaks if I try to pass an amper variable in the where string. It gives me an error about mssing quotes. Any ideas how I can get this to work?
-SET &SQLTEST = IF &DATETYPE EQ 'Bar Date' THEN ',a.assignment_id FROM PAL.SD sd, PAL.SD_ASSIGNMENT a WHERE a.sd_number = s.sd_number and a.begin_date >= &date1;'<br />-ELSE 'FROM PAL.SD sd;';<br /><br />SET SQLENGINE=SQLORA<br />SQL SET SERVER &MYSERV<br />SQL SELECT sd.sd_number,<br /> sd.doe_s_number<br /> &SQLTEST<br />END
August 01, 2005, 11:19 PMFrancis Mariani
Because you're embedding a DM variable inside another, you should use .EVAL.
You may also require quotes around the date value:
-SET &SQLTEST = IF &DATETYPE EQ 'BAR DATE'
- THEN ',A.ASSIGNMENT_ID FROM PAL.SD SD, PAL.SD_ASSIGNMENT A WHERE A.SD_NUMBER = S.SD_NUMBER AND A.BEGIN_DATE >= ''&DATE1.EVAL;'''
- ELSE 'FROM PAL.SD SD;';
August 04, 2005, 07:04 PMRobin Lovell
Here's a trimmed down version of one that works fine for us:
-DEFAULT &FRDATE = 'NONE' ;
-IF &FRDATE EQ 'NONE' GOTO ERR_DATE ;
-SET &FRDATEL = EDIT(&FRDATE,'9999/99/99') ;
-TYPE Getting calls since &FRDATEL ..
from cmgMeetingBucket b
where b.meetingDate >= "&FRDATEL"
TABLE FILE SQLOUT
ON TABLE HOLD AS H010 FORMAT ALPHA