Question

I am coding a program on Visual FoxPro that is retrieving data from .DBF files and I have some trouble with a SQL query. My program receives some input from the user, mainly some start and end time and dates.

My trouble is that I use the TEXTMERGE() command inside an INNERJOIN query which is itself in a loop. However, I am unable to make the relation between the two tables. The code that cause me trouble is something like:

SELECT Field1,Field2,Field3 FROM Table1 INNER JOIN TEXTMERGE("StrPath\Table<<i>>.DBF") ON Table1.Field1 = TEXTMERGE("StrPath\Table<<i>>.Field1")

with i being the incremental variable of the loop.

I know that it's the last part that causes me trouble, but I was unable to find a solution.

Thanks in advance for your help.

Was it helpful?

Solution

Doing a textmerge call for a query join sounds really ugly. However, it sounds like you have multiple tables of the same structure and trying to find common records, such as between table data that has been separated between years, or companies. Since you are already in a loop of "i", why not try to do something like...

for i = 2 to whatEverRange
  lcOtherTable = "strPath\Table" + allt( str( i ))

  select T1.Field1, T1.Field2, T1.Field3;
      from Table1  T1;
         inner join (lcOtherTable) TX;
            on T1.Field1 = TX.Field1;
      into cursor C_WhateverTempResultSet

   if reccount( "C_WhateverTempResultSet" ) > 0
      */ Do whatever with results

   endif 
endfor 

The (paren variable) will open the table you want, just give it a simplified "alias" (via TX) so you don't have to EVAL anything else. The correct "other" table will be used with the alias "TX", to your "ON" command can join T1.Field1 to TX.Field1... much easier to read and debug.

OTHER TIPS

The following will work.

SELECT Field1,Field2,Field3 
FROM Table1 INNER JOIN TEXTMERGE("StrPath\Table<<i>>.DBF") 
ON Table1.Field1 = EVAL(JUSTSTEM(JUSTFNAME(TEXTMERGE("StrPath\Table<<i>>"))) + [.Field1])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top