I try to pass date variable in open query but it shows error like
"Incorrect syntax near + "
Here is my query:
DECLARE @fromdt DATETIME = '2018-04-07';
DECLARE @EndDate1 DATETIME = '2018-04-07';
Select * from openquery(TIMEV,
'SELECT REPLACE(LTRIM(REPLACE(badgenumber,"0"," "))," ","0") badgenumber,
checktime as dt
from checkinout a
join USERINFO c on c.userid=a.userid
WHERE checktime >= '''''+CONVERT(CHAR(10), @fromdt, 120)+''''' AND ''''' + CONVERT(CHAR(10), @EndDate1, 120) + ''''' ')
I am stuck here .Thanks in advance..
OPENQUERYdocumentation explicitly forbids using any variables. So it's not a problem of converting, it's a problem of any variable being passed to it. Should be remedied, though, with something like in my answer. The provided link has multiple workarounds for this.