SQL查询-无法使用openquery正常工作

时间:2018-07-05 11:49:00

标签: sql-server-2008

我想在下面的查询中获取前一天的数据。

SELECT *
FROM OPENQUERY(SQL32BIT, 'SELECT DISTINCT * FROM OPENQUERY(SQL04, ''SELECT X.* FROM EMPLOYEES X WHERE X.E_JOINDATE = Curdate()'')')
GO

1 个答案:

答案 0 :(得分:0)

尝试一下:


Declare @MyQuery VARCHAR(4000),
        @printed_datetime DateTime
SET @printed_datetime = DATEADD(dd, - 1, GETDATE())
SET @MyQuery ='SELECT DISTINCT * FROM OPENQUERY(SQL04, 
              ''SELECT X.* FROM EMPLOYEES X WHERE X.E_JOINDATE =''''' + Convert(VarChar(20), @printed_datetime) + ''''''')';
exec(@MyQuery)