I have written some basic SQL in Oracle, which runs as expected. It selects a client, their ID and what 'services' they can provide.
However, when I add variables that are passed from VBA code the error message ORA-00907: Missing Right Parenthesis
occurs. It is due to an OR
in the code.
AND C.CURRENCY LIKE :cmbSelectAccountCcy
AND (S.SERVICEID LIKE :cmbSelectServiceType OR S.SERVICEID LIKE :cmbSelectServiceType2)
AND .... etc
If I remove the OR it runs as expected. The OR is part of a check that includes (at the end)
HAVING COUNT(S.SERVICEID) > 2
Allowing the 2 values to be checked, and only if the 2 (or more) are present display the client.
The combo boxes in Excel will pass the service ID as either a set value from the drop down box, or a %
character. I assume the right parenthesis is never reached in some cases.
What is the reason that I can run the SQL query with Hard Coded values, but not passing the very same variables through VBA? I have a Debug.Print()
statement in the VBA which is showing all the values I would expect to see passed over.
UPDATE:
Changing the name cmbSelectServiceType2
to cmbServiceTypeTwo
appears to have fixed the issue but, as of yet, I cannot figure out why. Any answers appreciated still! The only factor I can see is that the first is 21 chars, the second is < 20 chars. The column data type is VARCHAR2 in the table.
Tangent: The OR statement is now returning Service1 or Service1 and Service2 or Service2, i.e. a fully OR statement. The HAVING clause above was an attempt to impose that only BOTH are allowed.
UPDATE 2
Changing the '2' in cmbSelectServiceType2 to letters 'two' does not work. It seems like 20 chars is some arbitrary limit.