|
Home > Archive > FoxPro Help and Support > October 2005 > Help with Simple Do Statement
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Help with Simple Do Statement
|
|
|
| I'm trying to loop through database f:\table1.dbf, and for each record in
this table I need to run a SQL SELECT statement and sum some values to an
array. However, only the first record in f:\table1 is being used. What am I
doing wrong here that is preventing all records in f:\table1 from being used?
Thanks
sql_conn = sqlconnect("dsnname", "username", "")
Select 0
Use f:\table1 alias table1 in 0
Go top
Do while !eof()
sqlexec(sql_conn, "select * from transfer where tnum = '" + table1.trx_num
+ "'")
Select sqlresult
If !canceled
Sum table1.dollar_amt for trnstype_num = 1 to array[89]
Sum table1.dollar_amt for trnstype_num = 2 to array[89]
Endif
Skip
Enddo
| |
|
| simply issue a select table1 before your skip
you can also replace the do ... enddo
with a scan ... endscan and the select/skip would not be needed
Mike wrote:
> I'm trying to loop through database f:\table1.dbf, and for each record in
> this table I need to run a SQL SELECT statement and sum some values to an
> array. However, only the first record in f:\table1 is being used. What am I
> doing wrong here that is preventing all records in f:\table1 from being used?
> Thanks
>
> sql_conn = sqlconnect("dsnname", "username", "")
> Select 0
>
> Use f:\table1 alias table1 in 0
> Go top
> Do while !eof()
> sqlexec(sql_conn, "select * from transfer where tnum = '" + table1.trx_num
> + "'")
> Select sqlresult
> If !canceled
> Sum table1.dollar_amt for trnstype_num = 1 to array[89]
> Sum table1.dollar_amt for trnstype_num = 2 to array[89]
> Endif
> Skip
> Enddo
| |
| Fred Taylor 2005-10-27, 8:34 am |
| You need a SELECT table1 before you do GO TOP. Since you did a USE .. IN 0
that opens the table in the lowest available work area, which may not be
selected unless it happens to be 1. And you also need a SELECT table1
before your SKIP since you changed the workarea to sqlresult.
You'd be better off with:
SELECT 0
USE f:\table1
SCAN ALL
sqlexec(sql_conn, "select * from transfer where tnum = '" +
table1.trx_num + "'")
If !canceled
SELECT sqlResult
Sum table1.dollar_amt for trnstype_num = 1 to array[89]
Sum table1.dollar_amt for trnstype_num = 2 to array[89]
Endif
ENDSCAN
--
Fred
Microsoft Visual FoxPro MVP
"Mike" <Mike@discussions.microsoft.com> wrote in message
news:0BFD64A0-17F9-4A42-923C- C1C25F1E8010@microso
ft.com...
> I'm trying to loop through database f:\table1.dbf, and for each record in
> this table I need to run a SQL SELECT statement and sum some values to an
> array. However, only the first record in f:\table1 is being used. What
> am I
> doing wrong here that is preventing all records in f:\table1 from being
> used?
> Thanks
>
> sql_conn = sqlconnect("dsnname", "username", "")
> Select 0
>
> Use f:\table1 alias table1 in 0
> Go top
> Do while !eof()
> sqlexec(sql_conn, "select * from transfer where tnum = '" + table1.trx_num
> + "'")
> Select sqlresult
> If !canceled
> Sum table1.dollar_amt for trnstype_num = 1 to array[89]
> Sum table1.dollar_amt for trnstype_num = 2 to array[89]
> Endif
> Skip
> Enddo
|
|
|
|
|