declare @sql varchar(8000) set @sql = ' select login , logout from openquery([LinkedServerA], '' select login , logout from main.log_' + convert(char(6), getdate()-1, 112) + ''') WHERE login >= CONVERT(char(8), GETDATE()-1 , 112) AND logout < CONVERT(char(8), GETDATE() , 112) ' exec(@sql)
declare @sql varchar(8000) set @sql = ' select cast(login as datetime) login --讌朱 cast , logout from openquery([LinkedServerA], '' select cast(login as char(50)) login --覓語朱 cast , logout from main.log_' + convert(char(6), getdate()-1, 112) + ''') WHERE login >= CONVERT(char(8), GETDATE()-1 , 112) AND logout < CONVERT(char(8), GETDATE() , 112) ' exec(@sql)