Getting data from Postgres through Linked server of SQL I am trying to get the data from PostgreSql db through linked server of the SQL Server. But getting the following error on running this query
select * from openquery(SALESFORCE,'select closeddate
from case
where closeddate &gt; convert(datetime2, &quot;2020-01-01 00:00:00.0000000&quot;)')
OLE DB provider &quot;DBAmp.DBAmp&quot; for linked server &quot;SALESFORCE&quot; returned message &quot;Error: MALFORMED_QUERY:
where closeddate &gt; convert(datetime2, &quot;2020-01-01
^
ERROR at Row:3:Column:28
Bind variables only allowed in Apex code&quot;.
Msg 7320, Level 16, State 2, Line 21
Cannot execute the query &quot;select closeddate
from case1
where closeddate &gt; convert(datetime2, &quot;2020-01-01 00:00:00.0000000&quot;)&quot; against OLE DB provider &quot;DBAmp.DBAmp&quot; for linked server &quot;SALESFORCE&quot;.
Completion time: 2021-04-22T03:00:25.5943467-04:00
Where I am getting wrong
I think the problem is datetime2 is not a postgres data type:
convert(datetime2, &quot;2020-01-01 00:00:00.0000000&quot;)

The openquery statement exucute in the target database the query between '' so it must be written in the targewt dialect
try this

select * from openquery(SALESFORCE,'select closeddate from case where
closeddate &gt; cast(''2020-01-01'' as date)')