• sql concatenation

    Author
    Topic
    #354329

    Error in SQL concatenation

    I have built the followign code :

    Dim SQLCustomerOrder As String
    Dim SQLAfid As String
    Dim SQLBas As String
    SQLAfid = “AND ((Customers.afid)=1)”
    SQLBas = ” SELECT DISTINCT Customers.*, orders.paymentid, Customers.afid FROM Customers INNER JOIN orders ON (Customers.Customerid = orders.customerid) AND (Customers.Customerid = orders.customerid) WHERE (((orders.paymentid)=0) );”
    SQLCustomerOrder = SQLBas & SQLAfid
    Me.RecordSource = SQLCustomerOrder

    i have tried to divide a valid sql clasue into two parts, but i failed to do it
    and i receive the meesage “Characters found after end of sql clause”.

    The original and valid sql query was as follows

    SELECT DISTINCT Customers.*, orders.paymentid, Customers.afid
    FROM Customers INNER JOIN orders ON (Customers.Customerid = orders.customerid) AND (Customers.Customerid = orders.customerid)
    WHERE (((orders.paymentid)=0) AND ((Customers.afid)=1));

    It seems i cannot take out the And clause in the rigth way.

    ANy help?

    Viewing 0 reply threads
    Author
    Replies
    • #520466

      Your problem is the semicolon at the end of your SQLBas expression. To the query engine, that signals the end of the SQL. Then you concatenate another phrase to it and you get the error. If you remove the semicolon, it should work, although I don’t see why you have two joins on the same combination of fields in either query. You should be able to remove one of them.

    Viewing 0 reply threads
    Reply To: sql concatenation

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: