Thursday, January 20, 2005

Named References in VFP-SQL

VFP allows us to use named references for fieldnames, tablenames, filenames, etc with its various commands. But, not always with the SQL sub-language...

This works:

REPLACE ALL (crsUpdates.FieldName) ;
    WITH (crsUpdates.NewValue);
    FOR PrimaryKey = (crsUpdates.PK)

but not this:

UPDATE table1;
    SET (crsUpdates.FieldName) = (crsUpdates.NewValue) ;
    WHERE table1.PrimaryKey = (crsUpdates.PK)

or any of these...

UPDATE table1 ;
    SET &crsUpdates..FieldName = (crsUpdates.NewValue) ;
    WHERE table1.PrimaryKey = (

UPDATE table1 ;
    SET EVALUATE(crsUpdates.FieldName) = (crsUpdates.NewValue) ;
    WHERE table1.PrimaryKey = (

However, if you hard-code the SET field, it works:

UPDATE table1 ;
    SET MyField = (crsUpdates.NewValue) ;
    WHERE table1.PrimaryKey = (

I'm sure it's been this way forever -- I've just don't recall running across it before.

No comments: