开发者

How to split FoxPro records?

开发者 https://www.devze.com 2023-02-19 16:47 出处:网络
I have 60,000 records in the dbf file 开发者_JS百科in FoxPro. I want to split it into each 20,000 records (20000 * 3 = 60,000).

I have 60,000 records in the dbf file 开发者_JS百科in FoxPro. I want to split it into each 20,000 records (20000 * 3 = 60,000).

How can I achieve this?

I am new to FoxPro. I am using Visual FoxPro 5.0.

Thanks in advance.


You must issue a SKIP command when using the COPY command to make sure you are starting on the next record.

USE MyTable
GO TOP
COPY NEXT 20000 TO NewTable1
SKIP 1
COPY NEXT 20000 TO NewTable2
SKIP 1
COPY NEXT 20000 TO NewTable3


Todd's suggestion will work if you don't care how the records are split. If you want to divide them up based on their content, you'll want to do something like Stuart's first suggestion, though his exact answer will only work if the IDs for the records run from 1 to 60,000 in order.

What's the ultimate goal here? Why divide the table up?

Tamar


You can directly select from the first table:

SELECT * from MyBigTable INTO TABLE SmallTable1 WHERE ID < 20000
SELECT * from MyBigTable INTO TABLE SmallTable2 WHERE ID BETWEEN (20000, 39999)
SELECT * from MyBigTable INTO TABLE SmallTable3 WHERE ID > 39999

if you want more control, though, or you need to manipulate the data, you can use xbase code, something like this:

SELECT MyBigTable

scan
    scatter name oRecord memo

    if oRecord.Id < 20000
        select SmallTable1
        append blank
        gather name oRecord memo
    else if oRecord.Id < 40000
        select SmallTable2
        append blank
        gather name oRecord memo
    else 
        select SmallTable3
        append blank
        gather name oRecord memo
endscan 

It's been a while since I used VFP and I don't have it here, so apologies for any syntax errors.


use in 0 YourTable
select YourTable
go top
copy to NewTable1 next 20000
copy to NewTable2 next 20000
copy to NewTable3 next 20000


If you wanted to split based on record numbers, try this:

SELECT * FROM table INTO TABLE tbl1 WHERE RECNO() <= 20000
SELECT * FROM table INTO TABLE tbl2 WHERE BETWEEN(RECNO(), 20001, 40000)
SELECT * FROM table INTO TABLE tbl3 WHERE RECNO() > 40000
0

精彩评论

暂无评论...
验证码 换一张
取 消