Reputation: 9
I have been trying to access a dbf file. Complete an analysis and export it into a results.dbf.
This is what I am trying
CLEAR
USE SourceTable.dbf
CREATE TABLE OutputTable.dbf (col1 int, col2 numeric(5,2))
SELECT SourceTable.dbf
**analysis which is calculating life expectancy**
SCAN
col1 = col1 + 1
col2 = 1 / (1 - sourcetable.colB)
APPEND BLANK
REPLACE col1 WITH col1, col2 WITH col2
ENDSCAN
USE
CLOSE ALL
It keeps stating that I am not defining col2 but I am above
I am looking for an output file with col1 int, col2 numeric(5,2)
Upvotes: 0
Views: 160
Reputation: 2149
Vfp/FoxPro assumes that any "name" like for instance col2
is a column in the first place. If in your example there is another name col2
which is not an (alias.)column but rather a variable, then (why not choose a different name) and you'd want to use the alias names prefixes for the table.column names and the m.
prefix for the memvars, *and also preferably use the 'In' clauses with all xBase commands / functions that have one, especially when there are two different source&destination aliases/work-areas involved in your case, or even better use Vfp's SQL Insert Into command e.g.
APPEND BLANK IN destinationTable
REPLACE col1 WITH m.col1, col2 WITH m.col2 IN destinationTable
&&better/safer/faster/single-line:
INSERT INTO destinationTable (col1, col2) VALUES (m.col1, m.col2)
NB: the sample code you posted would not run because of syntax errors, e.g.:
col2 = 1 / (1 - sourcetable.colB) && where is colB coming from all of a sudden
&& avoid possible division by zero
SELECT SourceTable.dbf && invalid alias name, remove the orphaned extension
Upvotes: 4