myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


  


Help with an SMS Report

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
  Printable Version
All Forums >> [Management Products] >> Microsoft Systems Management Server >> Web Reporting >> Help with an SMS Report Page: [1]
Login
Message << Older Topic   Newer Topic >>
Help with an SMS Report - 6/5/2008 10:36:04 AM   
Tom_Watson

 

Posts: 92
Score: 4
Joined: 9/13/2006
Status: offline
I’m looking for a little help with a report I’m trying to build.  A basic description of what I am trying to do is compare the number of collection members for two collections (CollectionID: ABC0001F' and CollectionID: ABC00062), and I’m looking to do this per site.

As a starting point I did a quick report like so:-

quote:

SELECT   SiteCode,
        CollectionID,
        COUNT(ResourceID) AS [Count]
FROM     dbo.v_FullCollectionMembership
WHERE    CollectionID = 'ABC0001F' OR CollectionID = 'ABC00062'
GROUP BY SiteCode, CollectionID
ORDER BY SiteCode, CollectionID


This gives me a list like:-

Site Code|Collection ID|Count
ABC      |ABC0001F     |23
ABC      |ABC00062     |159
DEF      |ABC0001F     |37
DEF      |ABC00062     |634
GHI      |ABC0001F     |2
GHI      |ABC00062     |35


Etc…

However, what I’d really like to see is something like:-

Site Code|Collection ABC0001F Count|Collection ABC00062 Count
ABC      |23                       |159
DEF      |37                       |634
GHI      |2                        |35


Etc…

Maybe even add a 4th column with the difference between the two (column 3 minus column 2), and a final column with a percentage (column 4 divided by column 3).

My environment is SMS 2003 SP3 with SQL 2000 SP4, though we may be moving to SQL 2005 in a couple of weeks.

Tom Watson 

< Message edited by Tom_Watson -- 6/5/2008 10:46:50 AM >
Post #: 1
RE: Help with an SMS Report - 6/5/2008 1:00:36 PM   
Chr15Murr4y

 

Posts: 17
Score: 4
Joined: 3/28/2008
Status: offline
Hi Tom

I've not got access to test this right now but it should be something like this for the simple one..

SELECT distinct
colmem1.SiteCode,
(Select Count(colmem2.ResourceID) from dbo.v_FullCollectionMembership colmem2 where colmem2.sitecode = colmem1.sitecode and colmem2.collectionid = 'ABC0001F') as [Collection ABC0001F Count],
(Select Count(colmem2.ResourceID) from dbo.v_FullCollectionMembership colmem2 where colmem2.sitecode = colmem1.sitecode and colmem2.collectionid = 'ABC00062') as [Collection ABC00062 Count]
FROM     dbo.v_FullCollectionMembership colmem1
ORDER BY SiteCode

Or this if you want the difference and percentage.

SELECT distinct
colmem1.SiteCode,
(Select Count(colmem2.ResourceID) from dbo.v_FullCollectionMembership colmem2 where colmem2.sitecode = colmem1.sitecode and colmem2.collectionid = 'ABC0001F') as [Collection ABC0001F Count],
(Select Count(colmem2.ResourceID) from dbo.v_FullCollectionMembership colmem2 where colmem2.sitecode = colmem1.sitecode and colmem2.collectionid = 'ABC00062') as [Collection ABC00062 Count],
((Select Count(colmem2.ResourceID) from dbo.v_FullCollectionMembership colmem2 where colmem2.sitecode = colmem1.sitecode and colmem2.collectionid = 'ABC00062') - (Select Count(colmem2.ResourceID) from dbo.v_FullCollectionMembership colmem2 where colmem2.sitecode = colmem1.sitecode and colmem2.collectionid = 'ABC0001F')) as [Difference],
(((Select Count(colmem2.ResourceID) from dbo.v_FullCollectionMembership colmem2 where colmem2.sitecode = colmem1.sitecode and colmem2.collectionid = 'ABC00062') - (Select Count(colmem2.ResourceID) from dbo.v_FullCollectionMembership colmem2 where colmem2.sitecode = colmem1.sitecode and colmem2.collectionid = 'ABC0001F')) / (Select Count(colmem2.ResourceID) from dbo.v_FullCollectionMembership colmem2 where colmem2.sitecode = colmem1.sitecode and colmem2.collectionid = 'ABC00062')) as [Percentage]
FROM     dbo.v_FullCollectionMembership colmem1
ORDER BY SiteCode

It's not exactly refined, and it could be re-written a lot better but without being able to test it for you i wanted to leave it as uncomplicated as possible. You could replace the collections with variables too if you want.

Hope this works, i'll be able to test it tomorrow if it doesn't

C

(in reply to Tom_Watson)
Post #: 2
RE: Help with an SMS Report - 6/5/2008 5:16:54 PM   
jnelson993


Posts: 724
Score: 89
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
Hey Tom!

If you've got SQL 2005, we can make that even more sexy by using a PIVOT.

SELECT
  SiteCode AS [Site Code],
  [ABC0001F] AS [Collection ABC0001F Count],
  [ABC00062] AS [Collection ABC00062 Count],
  [ABC00062]-[ABC0001F] AS [Difference],
  ([ABC00062]-[ABC0001F])*100.0/[ABC00062] AS [Percentage]
FROM
(SELECT  
     SiteCode,
     CollectionID,
     ResourceID
  FROM    
     dbo.v_FullCollectionMembership
  WHERE
     CollectionID IN('ABC0001F','ABC00062')) as cnts
  PIVOT
  (COUNT(cnts.resourceID)
   FOR cnts.CollectionID IN ([ABC0001F],[ABC00062])) as pvt





< Message edited by jnelson993 -- 6/5/2008 5:18:37 PM >


_____________________________

Number2 (John Nelson)
MyITForum - Blog
MyITForum - Forum Posts

(in reply to Tom_Watson)
Post #: 3
RE: Help with an SMS Report - 6/6/2008 3:28:07 AM   
Tom_Watson

 

Posts: 92
Score: 4
Joined: 9/13/2006
Status: offline
Thanks John/Chris.

We may be going to SQL 2005 as ealy as next Wednesday.  So good news for everyone looking to use PIVOTs...

I'll give both of these samples a whirl, and let you know how they pan out.

PS. John, I have been doing a little bit more learning T-SQL, using the T-SQL Recipes book and a local install of SQL Express.  However, sometimes there are certain things I still can't get my head around.  At least as quick as some.

Cheers,
Tom

(in reply to jnelson993)
Post #: 4
RE: Help with an SMS Report - 6/6/2008 7:04:01 AM   
Tom_Watson

 

Posts: 92
Score: 4
Joined: 9/13/2006
Status: offline
Chris,

Your reports work as expected.

I may have to tinker with your second one slightly, as for one of the sites, both collections have 0 members, so when you work out the percentage you get a divide by zero error.

John, I'll have to wait for the sexy version until next week, when the SQL 2005 upgrade happens.

Thanks guys..

Tom Watson

(in reply to Tom_Watson)
Post #: 5
RE: Help with an SMS Report - 6/6/2008 9:06:28 AM   
Tom_Watson

 

Posts: 92
Score: 4
Joined: 9/13/2006
Status: offline
I tried using :-

SET ARITHABORT OFF
SET ANSI_WARNINGS OFF

from http://www.sql-server-helper.com/error-messages/msg-8134.aspx

but it looks like Web Reports don't like this.  It works OK in SQL Query Analyser though.

Anyway, I've used so far (based on Chris's second report):-

quote:

SELECT   DISTINCT colmem1.SiteCode,
                (SELECT COUNT(colmem2.ResourceID)
                 FROM   dbo.v_FullCollectionMembership colmem2
                 WHERE  colmem2.sitecode = colmem1.sitecode
                        AND colmem2.collectionid = 'ABC0001F') AS [Collection ABC0001F Count],
                (SELECT COUNT(colmem2.ResourceID)
                 FROM   dbo.v_FullCollectionMembership colmem2
                 WHERE  colmem2.sitecode = colmem1.sitecode
                        AND colmem2.collectionid = 'ABC00062') AS [Collection ABC00062 Count],
                ((SELECT COUNT(colmem2.ResourceID)
                  FROM   dbo.v_FullCollectionMembership colmem2
                  WHERE  colmem2.sitecode = colmem1.sitecode
                         AND colmem2.collectionid = 'ABC00062')
              - (SELECT COUNT(colmem2.ResourceID)
                  FROM   dbo.v_FullCollectionMembership colmem2
                  WHERE  colmem2.sitecode = colmem1.sitecode
                  AND colmem2.collectionid = 'ABC0001F')) AS [Difference],
                CASE
                  WHEN (SELECT COUNT(colmem2.ResourceID)
                        FROM   dbo.v_FullCollectionMembership colmem2
                        WHERE  colmem2.sitecode = colmem1.sitecode
                               AND colmem2.collectionid = 'ABC00062') = 0 THEN 100
                  ELSE (((SELECT COUNT(colmem2.ResourceID)
                          FROM   dbo.v_FullCollectionMembership colmem2
                          WHERE  colmem2.sitecode = colmem1.sitecode
                                 AND colmem2.collectionid = 'ABC00062')
                      - (SELECT COUNT(colmem2.ResourceID)
                          FROM   dbo.v_FullCollectionMembership colmem2
                          WHERE  colmem2.sitecode = colmem1.sitecode
                          AND colmem2.collectionid = 'ABC0001F'))
                       * 100
                      / (SELECT COUNT(colmem2.ResourceID)
                          FROM   dbo.v_FullCollectionMembership colmem2
                          WHERE  colmem2.sitecode = colmem1.sitecode
                          AND colmem2.collectionid = 'ABC00062'))
                END AS [Percentage]
FROM     dbo.v_FullCollectionMembership colmem1
ORDER BY SiteCode


It's starting to look like what I'm after.

Regards,
Tom Watson

< Message edited by Tom_Watson -- 6/6/2008 9:10:29 AM >

(in reply to Tom_Watson)
Post #: 6
RE: Help with an SMS Report - 6/6/2008 5:01:13 PM   
jnelson993


Posts: 724
Score: 89
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
AHHH, it burns my eyes!!!!

:)

I think everyone's way overthinking this.  Just create a query that counts them per collectionID/siteCode, then select from that query like a table (called a derived table for those that don't know) and do the math.  In my case, if you have a 0 for ABC00062 it won't do the division, it will just return NULL

SELECT
  cnt.SiteCode,
  cnt.ABC0001F AS [Collection ABC0001F Count],
  cnt.ABC00062 AS [Collection ABC00062 Count],
  cnt.ABC00062 - cnt.ABC0001F AS [Difference],
  CASE
     WHEN cnt.ABC00062 = 0 THEN NULL
     ELSE (cnt.ABC00062 - cnt.ABC0001F)*100.0/cnt.ABC00062
  END AS [Percentage]
FROM
(SELECT
     fcm.SiteCode,
     SUM(CASE fcm.CollectionID WHEN 'ABC0001F' THEN 1 ELSE 0 END) as [ABC0001F],
     SUM(CASE fcm.CollectionID WHEN 'ABC00062' THEN 1 ELSE 0 END) as [ABC00062]
  FROM
     dbo.v_FullCollectionMembership AS fcm
  WHERE
     fcm.CollectionID IN('ABC0001F','ABC00062')
  GROUP BY
     fcm.SiteCode) AS cnt





_____________________________

Number2 (John Nelson)
MyITForum - Blog
MyITForum - Forum Posts

(in reply to Tom_Watson)
Post #: 7
RE: Help with an SMS Report - 6/6/2008 5:03:16 PM   
jnelson993


Posts: 724
Score: 89
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
This is also nice on the SQL server...mine has a cost of 0.35...yours has to go to the well a bazillion times so it's got a cost of over 500 at my site.

_____________________________

Number2 (John Nelson)
MyITForum - Blog
MyITForum - Forum Posts

(in reply to jnelson993)
Post #: 8
RE: Help with an SMS Report - 6/9/2008 4:28:09 AM   
Tom_Watson

 

Posts: 92
Score: 4
Joined: 9/13/2006
Status: offline
Wow.  Looks much simpler.

Tom

(in reply to jnelson993)
Post #: 9
RE: Help with an SMS Report - 6/9/2008 5:45:22 AM   
Tom_Watson

 

Posts: 92
Score: 4
Joined: 9/13/2006
Status: offline
I thought I'd make this a little more complicated again, but simpler for the project managers that need these numbers to read.  I combined this with the standard report 77 "Sites by hierarchy with time of last site status update", and got:-

quote:

set nocount on

/* order sites by hierarchy */
create table #SiteOrder
(
SiteCode char(3),
SiteLevel    int,
PreOrder int identity,
PRIMARY KEY (SiteLevel,SiteCode)
)

declare @NextS char(3)
declare @SiteLevel int

set @SiteLevel=1
set @NextS=''
/* peform a depth first search of the site table, list the sites in pre-order */
while @NextS is not null
begin
  /* find the next child node */
  select @NextS=MIN(SiteCode) from v_Site
  where ReportingSiteCode=@NextS
    and SiteCode not in (select SiteCode from #SiteOrder
                                     where SiteLevel=@SiteLevel)

  if @NextS IS NULL
  begin
     set @SiteLevel=@SiteLevel-1
     /* pop up one level and find the last parent we were working with  */
     select @NextS = SiteCode from #SiteOrder where PreOrder=
           (select MAX(PreOrder) from #SiteOrder where SiteLevel=@SiteLevel-1)
  end
  else
  begin
     insert into #SiteOrder(SiteCode,SiteLevel) values(@NextS,@SiteLevel)
     /* move down one level and and find the children of this site */
     set @SiteLevel = @SiteLevel + 1
  end 
end

/* run the query, order by PreOrder, use SPACE with SiteLevel for indentation */ 

SELECT SPACE(3*(SiteLevel-1))+so.SiteCode as SiteCode,
      s.SiteName,
      cnt.ABC0001F AS [Collection ABC0001F Count],
      cnt.ABC00062 AS [Collection ABC00062 Count],
      cnt.ABC00062 - cnt.ABC0001F AS [Difference],
CASE
      WHEN cnt.ABC00062 = 0 THEN NULL
      ELSE ROUND((cnt.ABC00062 - cnt.ABC0001F)*100.0/cnt.ABC00062, 2)
END AS [Percentage]
FROM #SiteOrder so
JOIN v_Site s ON so.SiteCode=s.SiteCode
LEFT JOIN (SELECT
             fcm.SiteCode,
             SUM(CASE fcm.CollectionID WHEN 'ABC0001F' THEN 1 ELSE 0 END) as [ABC0001F],
             SUM(CASE fcm.CollectionID WHEN 'ABC00062' THEN 1 ELSE 0 END) as [ABC00062]
          FROM
             dbo.v_FullCollectionMembership AS fcm
          WHERE
             fcm.CollectionID IN('ABC0001F','ABC00062')
          GROUP BY fcm.SiteCode) AS cnt ON so.SiteCode=cnt.SiteCode
ORDER BY so.PreOrder

drop table #SiteOrder


A bit more complicated again though.

Tom

(in reply to Tom_Watson)
Post #: 10
RE: Help with an SMS Report - 6/24/2008 6:38:44 AM   
Tom_Watson

 

Posts: 92
Score: 4
Joined: 9/13/2006
Status: offline
BTW.  Our DBAs just installed SQL 2005 on the server.



Tom

(in reply to Tom_Watson)
Post #: 11
RE: Help with an SMS Report - 6/24/2008 10:35:02 AM   
jnelson993


Posts: 724
Score: 89
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
<tearing up> that's just beautiful!

Another 8 years and perhaps you'll be able to upgrade to SQL 2008!


_____________________________

Number2 (John Nelson)
MyITForum - Blog
MyITForum - Forum Posts

(in reply to Tom_Watson)
Post #: 12
RE: Help with an SMS Report - 6/24/2008 11:38:44 AM   
Tom_Watson

 

Posts: 92
Score: 4
Joined: 9/13/2006
Status: offline
Here's hoping.

PS.  Tried the sexual PIVOT report above, just for kicks.

Tom

(in reply to jnelson993)
Post #: 13
Page:   [1]
All Forums >> [Management Products] >> Microsoft Systems Management Server >> Web Reporting >> Help with an SMS Report Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts



  
Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.258