SQL Server中的OPENQUERY显示错误

时间:2018-04-07 13:58:28

标签: sql sql-server

我在查询下面使用链接服务器,但它显示错误。我错过任何报价吗?有人能帮助我吗?

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) + ''''' ')

1 个答案:

答案 0 :(得分:1)

我想你想要更像这样的东西:

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 >= CAST(''' + @fromdt + ''' as date)  AND CAST(''' + @EndDate1 + ''' as date)
';