SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query Trouble


Query Trouble

Author
Message
lmacdonald
lmacdonald
SSC Eights!
SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)

Group: General Forum Members
Points: 950 Visits: 564
Hi Everyone,

I'm a JR. DBA (MSSQL)

As so I'm still getting the hang out TSQL. I am trying to write a query that will sum up the important stats of replication, so I can later put them in a report.

select s.Name as Publisher,a.Publisher_DB as Published_DB, COUNT(a.article) as Article_Count,p.Publication
from MSarticles a join MSpublications p on
a.publication_id = p.publication_id join
sys.servers s on p.publisher_id = s.server_id
group by s.name,a.publisher_db, p.publication

The query above gets the publisher, published_db,article_count, and publication name. My boss wants me to add somethings that will include the status of the agents. So I tried adding a case expression on the MSreplication_monitordata.status column. However now when I run the query I get twice as many results, repeated rows of information and I don't get why. Can someone please help? Below is the code with added case.

SELECT s.Name as Publisher,a.Publisher_DB as Published_DB, COUNT(a.article) as Article_Count,p.Publication,
case rm.status
when '1' then 'Started'
when '2' then 'Succeeded'
when '3' then 'In Progress'
when '4' then 'Idle'
when '5' then 'Retrying'
when '6' then 'Failed'
End
from MSarticles a join MSpublications p on
a.publication_id = p.publication_id join
sys.servers s on p.publisher_id = s.server_id join
MSreplication_monitordata as rm on p.publication_id = rm.publication_id
group by s.name,a.publisher_db, p.publication,rm.status

On a non related note, anyone know a good source for policy management templates and common uses? Happy Friday.
lmacdonald
lmacdonald
SSC Eights!
SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)SSC Eights! (950 reputation)

Group: General Forum Members
Points: 950 Visits: 564
Well shoot I hate it when I post too soon! I found it was returning double because there where two agent types per publication, so a where clause on the type field fixed it.
Now, how can I delete this post.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search