Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. SELECT ( CASE
  2. WHEN mdh.runstatus = '1' THEN 'Start - ' + CAST(
  3. mdh.runstatus AS VARCHAR)
  4. WHEN mdh.runstatus = '2' THEN 'Succeed - ' + CAST(
  5. mdh.runstatus AS VARCHAR)
  6. WHEN mdh.runstatus = '3' THEN 'InProgress - ' + CAST(
  7. mdh.runstatus AS VARCHAR)
  8. WHEN mdh.runstatus = '4' THEN 'Idle - ' + CAST(mdh.runstatus AS
  9. VARCHAR)
  10. WHEN mdh.runstatus = '5' THEN 'Retry - ' + CAST(
  11. mdh.runstatus AS VARCHAR)
  12. WHEN mdh.runstatus = '6' THEN 'Fail - ' + CAST(mdh.runstatus AS
  13. VARCHAR)
  14. ELSE CAST(mdh.runstatus AS VARCHAR)
  15. END ) [Run Status],
  16. mda.subscriber_db [Subscriber DB],
  17. mda.publication [PUB Name],
  18. RIGHT(LEFT(mda.name, Len(mda.name) - ( Len(mda.id) + 1 )),
  19. Len(LEFT(mda.name, Len(mda.name) - ( Len(mda.id) + 1 ))) - (
  20. 10 + Len(mda.publisher_db) + ( CASE
  21. WHEN mda.publisher_db = 'ALL' THEN 1
  22. ELSE Len(mda.publication) + 2
  23. END ) )) [SUBSCRIBER],
  24. CONVERT(VARCHAR(25), mdh.[time]) [LastSynchronized],
  25. und.undelivcmdsindistdb [UndistCom],
  26. mdh.comments [Comments],
  27. 'select * from distribution.dbo.msrepl_errors (nolock) where id = ' +
  28. CAST(mdh.error_id AS VARCHAR(8)) [Query More Info],
  29. mdh.xact_seqno [SEQ_NO],
  30. ( CASE
  31. WHEN mda.subscription_type = '0' THEN 'Push'
  32. WHEN mda.subscription_type = '1' THEN 'Pull'
  33. WHEN mda.subscription_type = '2' THEN 'Anonymous'
  34. ELSE CAST(mda.subscription_type AS VARCHAR)
  35. END ) [SUB Type],
  36. mda.publisher_db + ' - ' + CAST(mda.publisher_database_id AS VARCHAR)
  37. [Publisher DB],
  38. mda.name
  39. [Pub - DB - Publication - SUB - AgentID]
  40. FROM distribution.dbo.msdistribution_agents mda
  41. LEFT JOIN distribution.dbo.msdistribution_history mdh
  42. ON mdh.agent_id = mda.id
  43. JOIN (SELECT s.agent_id,
  44. maxagentvalue.[time],
  45. SUM(CASE
  46. WHEN xact_seqno > maxagentvalue.maxseq THEN 1
  47. ELSE 0
  48. END) AS undelivcmdsindistdb
  49. FROM distribution.dbo.msrepl_commands t (nolock)
  50. JOIN distribution.dbo.mssubscriptions AS s (nolock)
  51. ON ( t.article_id = s.article_id
  52. AND t.publisher_database_id = s.publisher_database_id
  53. )
  54. JOIN (SELECT hist.agent_id,
  55. MAX(hist.[time]) AS [time],
  56. h.maxseq
  57. FROM distribution.dbo.msdistribution_history hist (
  58. nolock)
  59. JOIN (SELECT agent_id,
  60. Isnull(MAX(xact_seqno), 0x0) AS
  61. maxseq
  62. FROM
  63. distribution.dbo.msdistribution_history (
  64. nolock)
  65. GROUP BY agent_id) AS h
  66. ON ( hist.agent_id = h.agent_id
  67. AND h.maxseq = hist.xact_seqno )
  68. GROUP BY hist.agent_id,
  69. h.maxseq) AS maxagentvalue
  70. ON maxagentvalue.agent_id = s.agent_id
  71. GROUP BY s.agent_id,
  72. maxagentvalue.[time]) und
  73. ON mda.id = und.agent_id
  74. AND und.[time] = mdh.[time]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement