******************************************************************************** >FUNCTION ADDALIAS( tcExpr, tcAlias ) >******************************************************************************** >* >* OVERVIEW: Adds the alias name to a list of field names contained in an >* index expression so that alias and field names are paired, and >* returns the amended expression. >* >* EXAMPLE: ADDALIAS( "sys_code + pipe", "ansurvey" ) -> >* "ansurvey.sys_code + ansurvey.pipe" >* >* PARAMETERS: tcExpr The index expression to which alias is to be added >* tcAlias The alias name to be added. >* >* RETURN: (C) The index expression with alias name added to each field >* name in the expression. >* >LOCAL lnNumFields, lcExpr, lcThisField, lnThisFieldPosition, lnI, lcAliasedExpr > >DO WHILE " " $ tcExpr > tcExpr = STRTRAN( tcExpr, " ", "" ) >ENDDO > >* Get the number of fields in the expression >lnNumFields = OCCURS( '+', tcExpr ) + 1 > >* This variable will be used to hold the amended expression with alias name >* added to each field in the expression. >lcAliasedExpr = '' > >* NOTE: There is no testing to determine whether the field is actually in the >* specified table. Testing if wanted should be added here. >FOR lnI = 1 TO lnNumFields > > IF lnI = lnNumFields > lcThisField = lcExpr > ELSE > lcThisField = LEFT( lcExpr, AT( '+', lcExpr ) - 1 ) > ENDIF > > IF OCCURS( '( ', lcThisField ) > 0 > lnThisFieldPosition = ; > AT( '( ', lcThisField, OCCURS( '( ', lcThisField ) ) + 1 > ELSE > lnThisFieldPosition = 0 > ENDIF > > lcAliasedExpr = ; > lcAliasedExpr + IIF( !EMPTY( lcAliasedExpr ), '+', '' ) + ; > STUFF( lcThisField, lnThisFieldPosition, 0, tcAlias + '.' ) > > lcExpr = SUBSTR( lcExpr, AT( '+', lcExpr ) + 1 ) > >NEXT > >RETURN lcAliasedExpr > >ENDFUNC && ADDALIAS()>