Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Where statement is not parsed correctly for a linked server query

Hello, I'm getting the following error:

OLE DB provider "DBAmp.DBAmp" for linked server "salesforce" returned message "Error 13005 : Error translating SQL statement: line 1:240: unexpected token: )".
Msg 7320, Level 16, State 2, Procedure Calculate opened/closed cases, Line 35
Cannot execute the query "SELECT "Tbl1006"."Date__c" "Col1013","Tbl1006"."Id" "Col1014" FROM "statistics__c" "Tbl1006" WHERE "Tbl1006"."Date__c"=? AND (("Tbl1006"."Type__c"=? OR "Tbl1006"."Type__c"=?) AND ?=(0) OR "Tbl1006"."Type__c"=?)" against OLE DB provider "DBAmp.DBAmp" for linked server "salesforce".

Here's the statement that causes it:

select id
from salesforce...statistics__c
where date__c = @d1 and (
((type__c = @typeO or type__c = @typeC)
and @ActiveOnly = 0) or
type__c = @typeA)
order by date__c;

variable @ActiveOnly is of type bit. Salesforce is the name of a linked server, statistics__c a custom table. The query works fine if the AND/OR condition is removed.
1 person has
this problem