首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否使用数组或游标更新具有相同结构的多个表?

问是否使用数组或游标更新具有相同结构的多个表?
EN

Stack Overflow用户
提问于 2014-01-17 07:54:17
回答 3查看 1.5K关注 0票数 0

使用VFP 6.0...我正在尝试查看是否可以使用数组或游标中的数据字段更新多个表。因此,例如,我将创建一个游标,并将txt文件中的数据附加到它:

代码语言:javascript
复制
create cursor cTemp(acct c(5), field c(5), newscript c(25))
append from file delimited with tab

我想要建立一个循环,它将使用第一个字段( ...Now )来查找表,然后使用游标中的字段& newscript更新表。在update命令中使用字段作为字段名时遇到问题:

代码语言:javascript
复制
UPDATE acct\table SET &field = newscript

由于字段将根据acct\table而变化,因此我需要在脚本中灵活使用它。

EN

回答 3

Stack Overflow用户

发布于 2014-01-17 08:54:25

您首先需要使用内存变量(而不是表中的字段)来使用宏扩展"&“。因此,从:f_name=field(1)开始,将表的第一个字段捕获到一个变量中。然后在UPDATE table SET &f_name = value上执行循环

票数 1
EN

Stack Overflow用户

发布于 2014-01-17 17:43:34

代码语言:javascript
复制
Create Cursor cTemp(acct c(5), Field c(5), newscript c(25))
Append From myfile Delimited With Tab

Select cTemp

Scan

* -- Copy values of current record to an object.
    Scatter Name loThis

    * -- Assumes target table is already open. If not add code to open it.
    * -- Also assumes you want to update all records in target table.
    Replace All (loThis.Field) With loThis.newscript In (loThis.acct)

Endscan
票数 0
EN

Stack Overflow用户

发布于 2014-01-18 11:51:19

很难确切地说出您所说的更新帐户\表...我假设每个表都被称为" table“,但"acct”就是文件夹。在我的示例中,您将有c:\tmp\t1\ctable,c:\tmp\t2\ctable,c:\tmp\t3\ctable (顺便说一句,对于表名和字段名这样的保留字,使用TABLE和FIELD这样的保留字并不是很酷)。

如果设置了c:\tmp,则可以按原样运行此代码。最后,将每个表中包含"xxxxx“的1条记录更改为游标记录中列出的数据。

代码语言:javascript
复制
* I have a tmp folder. In it I created 3 subfolders: t1, t2, t3.
set default to c:\tmp
* All tables are the same name (ctable). First table in folder t1 with field name cf10
create table t1\ctable (cf10 c(25))
* Insert a record with "xxxxx" as the data
insert into ctable values ("xxxxx")
* this will show you what is in the table. escape to let the program run.
brow last
use

* 2nd table, field is called cf8.
create table t2\ctable (cf8 c(25))
insert into ctable values ("xxxxx")
brow last
use

* 3rd table, field is called cf6
create table t3\ctable (cf6 c(25))
insert into ctable values ("xxxxx")
brow last
use

* create cursor, add 3 records (this is just for testing... this would be like your appending of the text file).
create cursor cTemp(acct c(5), cfield c(5), newscript c(25))
insert into ctemp values ("t1","cf10","data for field10")
insert into ctemp values ("t2","cf8","data for field8")
insert into ctemp values ("t3","cf6","data for field6")
* so I am telling the cursor to update unique field names in a table called CTABLE with unique data
scan
    m.lcExecString="UPDATE " + alltrim(acct)+"\ctable SET "+cfield+"='"+alltrim(newscript)+"'"
    &lcExecString
    select ctable
    browse last
    * make sure to close the file you are updating
    use in select("ctable")
endscan
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21175361

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档