I am trying to run a select using openquery
with filtering result by date, but I have problem with using the date after where clause.
Ideally I would like to be able to pass a variable
set @d = dateadd(day, -30, getdate())
but for the sake of example I will try to use specified date :
Example:
select *
from OPENQUERY([Linked_Server], 'select id, name from Users where LastModifiedDate > ''2017-01-01''')
This returns an error:
INVALID_FIELD:
select id, name from Users where LastModifiedDate > '2017-01-01'
value of filter criterion for field 'LastModifiedDate' must be of type dateTime and should not be enclosed in quotes".
It works ok if I use for example istrue = true
, but comparing dates seems to be the problem.
Can someone please advise me on this ?