> 1. The following code
>
> VNRCRT=0
> SELECT NRCRT() AS NC,NAME FROM ADDBOOK
>
> FUNCTION NRCRT
> VNRCRT=VNRCRT+1
> RETURN VNRCRT
>
> return the following cursor :
>
> nc name
> == =====
> 2 john
> 3 mark
> ....
>
> It seems that NRCRT() is called twice for the first record. Is
> this a feature? Is this a bug? There is any (logical) reason for
> this behaviour?
The reason is that FoxPro evaluates the expressions in the SELECT clause
once for the source data. This way it can build an appropriate
structure to send the information to.
BTW: this is one reason that you should _never_ use TRIM() as the
outside function in a SELECT expression. If there is no data in the row
that FoxPro evaluates, the output length will be 0.
> 2. I'm using something like :
>
> SELECT FIELD1, FIELD2, UDF1() AS CFIELD1 FROM TABLEA INTO CURSOR CURSOR1
>
> The UDF1 return a numeric value. There is any way to force VFP to create
> the CFIELD1
> cursor field with a specified lenght and decimal digits?
There are two ways. The first is reliable, the second works a lot of
the time, but you should test it before shipping it.
1) SELECT space(10) as FIELD1, ;
space(20) as FIELD2, ;
0000.00 as CField1 ;
FROM TABLEA ;
WHERE .F.
UNION ALL
SELECT FIELD1, ;
FIELD2, ;
SUM(value) as CField1 ;
etc.
The first SELECT will create the structure with no information. The
second SELECT will populate the structure. This means that you have to
know the size of all of the fields before you start.
2) SELECT FIELD1, ;
FIELD2, ;
UDF1() as CField1 ;
FROM TABLEA ;
etc.
PROCEDURE UDF1
m.lnReturn = 12.34
return val(str(m.lnReturn,10,2))
This will create a format for the number. This will frequently work,
but not always. As ever -- test it well before you ship it.
> 3. I have a table like
>
> DATE AMOUNT
> ==== =======
> 01/01 10
> 01/02 5
> 01/05 7
>
> There is any way to create a cursor with a "running total" additional
> field
> like
>
> DATE AMOUNT TOTAL
> ==== ======= =======
> 01/01 10 10
> 01/02 5 15
> 01/05 7 22
>
> using only one SQL select without any UDF?
Is the result of this going to be output to a report form? If so, you
can perform the accumulation on the report form itself.
I can't think of any way to do it in FoxPro's implementation of SELECT.
/Paul