0

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.

4

2 回答 2

1

为查询连接执行 textmerge 调用听起来真的很难看。但是,听起来您有多个相同结构的表,并试图找到共同的记录,例如在不同年份或公司之间分离的表数据之间。既然您已经处于“i”循环中,为什​​么不尝试做类似...

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 

(paren 变量)将打开您想要的表,只需给它一个简化的“别名”(通过 TX),这样您就不必 EVAL 其他任何东西。正确的“其他”表将与别名“TX”一起使用,您的“ON”命令可以将 T1.Field1 连接到 TX.Field1...更易于阅读和调试。

于 2013-05-28T00:43:05.533 回答
0

以下将起作用。

SELECT Field1,Field2,Field3 
FROM Table1 INNER JOIN TEXTMERGE("StrPath\Table<<i>>.DBF") 
ON Table1.Field1 = EVAL(JUSTSTEM(JUSTFNAME(TEXTMERGE("StrPath\Table<<i>>"))) + [.Field1])
于 2013-05-27T21:37:51.393 回答