General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
We use the following query in production now. It has a mixture of macro sub and () evals in select clauses. we build the selection clauses elsewhere and the where filter. A lot of the stuff is data driven like getting the 3 letter alias from a table to build the field selection ( e.g. ans.fieldname) etc...
It works good so far...
IF !EMPTY(thisform.c_WhereFilt)
lcWhere = 'WHERE ' + thisform.c_WhereFilt && built in another method
ELSE
lcWhere = ''
ENDIF
IF !EMPTY(thisform.c_AnsFields)
lcAnsFields = thisform.c_AnsFields && built in another method
ELSE
lcAnsFields = ''
ENDIF
* set the join condition based on the user selection
DO CASE
CASE thisform.l_AllTestPoints
lcTstAnsJoin = 'LEFT OUTER JOIN '
CASE thisform.l_ReadingOnly
lcTstAnsJoin = 'INNER JOIN '
OTHERWISE
lcTstAnsJoin = 'INNER JOIN '
ENDCASE
lcSelCursor = sellist() && get the select cursor name
SELECT tst.*, ;
&lcAnsFields ;
tsf.location, ;
tsf.equation, ;
tsf.legal ;
FROM tstpoint tst ;
INNER JOIN tstfac tsf ;
ON &gcTsfTstJn ; && constant define join condition
(lcTstAnsJoin) ansurvey ans ;
ON &gcTstAnsJn ; && constant define join condition
INNER JOIN nodes nde ;
ON nde.ndesyscode = tsf.sys_code ;
INNER JOIN &lcSelCursor sel ;
ON tsf.sys_code + tsf.pipe = sel.sys_code + sel.pipe ;
&lcWhere ;
INTO CURSOR cAnsreads NOFILTER
MW
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only