sqlvisual-foxpro

How do I use a view parameter as a field in native Foxpro SQL statement


I am using VFEGenview to create my view. The view I am trying to create has complex joins so I can not use VFP's View Designer because it would mess up my joins. Using VFEGenView and just trying to create a simple view to test inclusion of a view parameters value as a field in my view, I get an error.

My code:

DBSetProp('VL_CUSTOMERS', 'View', 'ParameterList', "vp_ccommmenus_id,'C'")

CREATE SQL VIEW "VL_Customers" ;    
AS 
    SELECT Customers.cid,;
        Customers.ccustomer_number,;        Customers.ccustomer_name,;
        ?vp_commmenus_id as ccommmenus_id;  FROM INMATETRUSTFUND!Customers

I have tried :?vp_commmenus_id, &?vp_commmenus_id and &vp_commmenus_id all of which result in an error:

vp_commmenus_id is not found

Thanks, John


Solution

  • There are superfluous line-continuation characters ";" in the code you posted. But first of all, a Vfp SQL View Parameter needs to be in scope in the very moment when you want "use" it, i.e. when the "Create [SQL] View ..." statement runs in your case, as well as when you open it, i.e. Use theView, or when you would Requery("theView").

    Just tried the following sequence in the Vfp "Command Window":

    * first Change Directory to the desired "Test" File-System folder:
    CD D:\Temp
    CREATE DATABASE Test55
    CREATE TABLE test56 (col1 Int)
    INSERT INTO test56 VALUES (8)
    
    CREATE VIEW vTest as Select col1, ?p1 From test56 && throws an Error 1806 as you noted
    
    p1 = "x" && create the variable first
    CREATE VIEW vTest as Select col1, ?p1 From test56 && works now
    
    USE vtest
    BROWSE
    

    enter image description here