我想在下面的查询中获取前一天的数据。
SELECT *
FROM OPENQUERY(SQL32BIT, 'SELECT DISTINCT * FROM OPENQUERY(SQL04, ''SELECT X.* FROM EMPLOYEES X WHERE X.E_JOINDATE = Curdate()'')')
GO
答案 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)