******************************************************************** * Description.......: InsertAlias - inserts alias before each field in a string * Calling Samples...: * Parameter List....: tcStr, tcAlias * Created by........: Nadya Nosonovsky 08/06/2001 01:34:01 PM * Modified by.......: ******************************************************************** lparameter tcStr, tcAlias ** No check for parameters passed **** First change AND and OR tcStr=strtran(m.tcStr,".OR."," OR ") tcStr=strtran(m.tcStr,".AND."," AND ") local lcDigits, lcSymbols, lcChars, lnFields, lnI, array laFields[1], lcChar, lcField lcDigits=[0123456789] lcChars=[QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm] lcSymbols=alltrim(chrtran(m.tcStr,m.lcDigits+m.lcChars+['"]+"[]","")) ** Assume, that the table is opened, no check for this for lnI=1 to len(m.lcSymbols) lcChar=substr(m.lcSymbols,m.lnI,1) tcStr=strtran(m.tcStr,m.lcChar," "+m.lcChar+" ") next tcStr=" "+m.tcStr+" " lnFields=afields(laFields) for lnI=1 to m.lnFields lcField=laFields[m.lnI,1] tcStr=strtran(m.tcStr," "+m.lcField+" "," "+m.tcAlias+"."+m.lcField+" ") next if not "foxtools" $ lower(set('library')) set library to foxtools additive endif tcStr=reduce(m.tcStr) return alltrim(m.tcStr) && this string would contain spaces, but I don't think, it's a problem>
* Get the list of the fields into array in descending order by the field name lenght >Select Mytable >= Afields(laList) >FOR i=1 TO ALEN(laList,1) > Lalist[i,2] = Len(Trim(Lalist[i,2]) >ENDFOR >ASORT(laList,2, 1) > >* Translate all names into unique @nnn format >FOR i=1 TO ALEN(laList,1) > STRTRAN(lcWhere, Trim(laList[i,1]), "@" + PADL(i, 3, "0")) >ENDFOR > >* Translate back adding "aa." >FOR i=1 TO ALEN(laList,1) > STRTRAN(lcWhere, "@" + PADL(i, 3, "0"), "aa." + Trim(laList[i,1]) ) >ENDFOR >>
lcStr=where CODE#PARENTCODE.OR.PCOFLAG="P">>>>