1

有谁知道从 sql server (2008) 查询上次同步日期。

它与复制监视器中显示的信息相同,但我希望能够从查询中获取该日期。

4

3 回答 3

3

我创建了一个这样的视图来获取订阅者的最后日期

select subscriber_name, max(start_time) as last_sync 
from msMerge_sessions inner join msMerge_agents 
   on msmerge_agents.id = msmerge_sessions.agent_id 
group by subscriber_name

我将视图称为“LastSync” - 然后我像这样加入该视图以获得类似于复制监视器显示的表示。

SELECT     dbo.LastSync.id, dbo.LastSync.subscriber_name, dbo.LastSync.creation_date, dbo.LastSync.last_sync, 
                  distribution.dbo.MSmerge_sessions.estimated_upload_changes + distribution.dbo.MSmerge_sessions.estimated_download_changes AS estimate_rows, 
                  distribution.dbo.MSmerge_sessions.upload_inserts + distribution.dbo.MSmerge_sessions.upload_updates + distribution.dbo.MSmerge_sessions.upload_deletes + distribution.dbo.MSmerge_sessions.download_inserts
                   + distribution.dbo.MSmerge_sessions.download_updates + distribution.dbo.MSmerge_sessions.download_deletes AS actual_rows, 
                  distribution.dbo.MSmerge_sessions.duration AS total_seconds, distribution.dbo.MSmerge_sessions.percent_complete, 
                  distribution.dbo.MSmerge_sessions.delivery_rate, CASE (runstatus) 
                  WHEN 1 THEN 'Start' WHEN 2 THEN 'Succeed' WHEN 3 THEN 'In Progress' WHEN 4 THEN 'Idle' WHEN 5 THEN 'Retry' WHEN 6 THEN 'Fail' END AS Status
FROM         distribution.dbo.MSmerge_sessions INNER JOIN
                  dbo.LastSync ON dbo.LastSync.id = distribution.dbo.MSmerge_sessions.agent_id AND distribution.dbo.MSmerge_sessions.start_time = dbo.LastSync.last_sync
于 2012-01-04T18:38:22.270 回答
2

通过使用系统表 msMerge_sessions,您可以看到很多有关合并会话的信息:

select * from msMerge_sessions

根据您需要的信息,使用数据库中可用的其他系统表。

于 2008-12-18T11:05:32.370 回答
0

对于已回答的数字 3

很大的努力,但有一些修改关于运行查询的能力视图

---- 创建视图 LastSync 如下

Create View LastSync As 
select subscriber_name, max(start_time) as last_sync, ID, creation_date
from msMerge_sessions inner join msMerge_agents 
   on msmerge_agents.id = msmerge_sessions.agent_id 
group by subscriber_name, ID, creation_date
Go

---- 在下面运行查询

选择 dbo.LastSync.id、dbo.LastSync.subscriber_name、dbo.LastSync.creation_date、dbo.LastSync.last_sync、distribution.dbo.MSmerge_sessions.estimated_upload_changes + distribution.dbo.MSmerge_sessions.estimated_download_changes AS estimate_rows、distribution.dbo.MSmerge_sessions.upload_inserts + distribution.dbo.MSmerge_sessions.upload_updates + distribution.dbo.MSmerge_sessions.upload_deletes + distribution.dbo.MSmerge_sessions.download_inserts + distribution.dbo.MSmerge_sessions.download_updates + distribution.dbo.MSmerge_sessions.download_deletes AS actual_rows,distribution.dbo.MSmerge_sessions.duration AS total_seconds,distribution.dbo.MSmerge_sessions.percent_complete,distribution.dbo.MSmerge_sessions.delivery_rate,CASE(运行状态) WHEN 1 THEN 'Start' WHEN 2 THEN 'Succeed' WHEN 3 THEN '进行中' WHEN 4 THEN 'Idle' WHEN 5 THEN 'Retry' WHEN 6 THEN 'Fail' END AS Status FROM distribution.dbo.MSmerge_sessions INNER JOIN dbo.LastSync ON dbo.LastSync.id = distribution.dbo.MSmerge_sessions.agent_id AND distribution.dbo.MSmerge_sessions.start_time = dbo.LastSync.last_sync

- 祝你好运

于 2018-02-07T13:13:47.147 回答