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:


  


v_GS_COMPUTER_SYSTEM / Computer_System_DATA has more than one row per machine.

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

Logged in as: Guest
  Printable Version
All Forums >> [Management Products] >> System Center Products >> System Center Configuration Manager >> v_GS_COMPUTER_SYSTEM / Computer_System_DATA has more than one row per machine. Page: [1]
Login
Message << Older Topic   Newer Topic >>
v_GS_COMPUTER_SYSTEM / Computer_System_DATA has more th... - 11/13/2008 3:47:33 PM   
MikeTeske

 

Posts: 3
Score: 0
Joined: 11/13/2008
Status: offline
Orginally posted on Microsft Tecnet

Hi,
 
I have a query that returns the Last Scan Date, Name, Make and Model of machines scanned in the last 10 days.
 
DECLARE @dLastScanDate DATETIME
SELECT @dLastScanDate = getdate() -10
SELECT A.LastHWScan,
B.Name0,
B.Manufacturer0,
B.Model0,
FROM v_GS_WORKSTATION_STATUS A
JOIN v_GS_COMPUTER_SYSTEM B ON A.ResourceID = B.ResourceID
WHERE A.LastHWScan > @dLastScanDate
 
I have 13 machines with two rows v_GS_COMPUTER_SYSTEM.  This is from a total of over 60,000.
 
The primary key of the base tables WorkstationStatus_DATA is MachineID, and for
Computer_System_DATA it is MachineID,InstanceKey
 
It looks like the 13 machines were rebuilt with a new name.
 
How do I know which is the current one?
 
I could use the most recent TimeKey but that seems resource intensive to join the table back to itself with a max(TimeKey)
 
Any insight would be most appreciated
 
 
Thanks.
 
Mike.
 
The data in v_GS_WORKSTATION_STATUS  contains one row per machine.
 
v_GS_COMPUTER_SYSTEM contains information about the machines.
 
In my mind this should be a one to one relationship.  A machine should have one Name, Make and Model.
 
Here is an example where this is not the case:
 
select machineid,lasthwscan from WorkstationStatus_Data where machineid = 1782
 
machineid   lasthwscan                                            
----------- ------------------------------------------------------
1782        2008-11-08 17:47:00.000

select machineid,instancekey,name0,model0,manufacturer00 from computer_system_data where machineid = 1782
 
machineid   instancekey name0      model0           manufacturer00   
----------- ----------- ---------- ---------------- -----------------
1782        1           aaaaaaa    Latitude D630    Dell Inc.
1782        1           xxxxxxx    Latitude D630    Dell Inc.
 
 
When I join these tables I want one row.  How do I pick the correct one? Is  Name0 = aaaaaaa or xxxxxx?
 
I can do this
 
DECLARE @dLastScanDate DATETIME
SELECT @dLastScanDate = getdate() -10
SELECT A.LastHWScan,
B.Name0,
B.Manufacturer0,
B.Model0
FROM v_GS_WORKSTATION_STATUS A
JOIN v_GS_COMPUTER_SYSTEM B ON A.ResourceID = B.ResourceID
join (select resourceID,max(TimeStamp) max_TimeStamp
     from v_GS_COMPUTER_SYSTEM group by resourceid) c on c.ResourceID = b.ResourceID and b.TimeStamp = c.max_TimeStamp
WHERE A.LastHWScan > @dLastScanDate
 
Which used the most recent timestamp from v_GS_COMPUTER_SYSTEM, but I don't think that is very logical and my query goes from 2 seconds to 26 in a test database with 2000 machines.
 
 
I could join to System_Disc which has Netbios_Name0 and Name0, (which one is the right field?  All of mine are equal) but all of these approaches seem to indicate something wrong with my data.  Should there be more than one row per machine in v_GS_COMPUTER_SYSTEM?  The data model allows it, but it does not make sense to me.
 
Run this to check your databases

select count(*),machineid
from computer_system_data
group by machineid
having count(*) > 1
 
Thanks.
 
Post #: 1
RE: v_GS_COMPUTER_SYSTEM / Computer_System_DATA has mor... - 11/13/2008 4:04:36 PM   
jnelson993


Posts: 959
Score: 132
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
Well, I hope you have SQL 2005 or higher...

The trick is to pick out only the highest timestamp, right?  So to do that, I like to use the ROW_NUMBER function which will kind of rank them according to the order you specify.  Then select only the items from that subquery where the row is #1.  something like this: (Oh, and I removed the variable declaration and moved the logic to the where clause since it wasn't necessary):
SELECT
  wss.LastHWScan,
  cs.Name0,
  cs.Manufacturer0,
  cs.Model0
FROM
  (SELECT
     ResourceID,
     Name0,
     Manufacturer0,
     Model0,
     ROW_NUMBER() OVER(PARTITION BY resourceID ORDER BY TimeStamp DESC) AS Position
  FROM  
     dbo.v_GS_COMPUTER_SYSTEM) AS cs

  INNER JOIN dbo.v_GS_Workstation_Status AS wss
     ON cs.ResourceID = wss.ResourceID
WHERE
   cs.Position = 1
  AND wss.LastHWScan > getdate() - 10




_____________________________

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

(in reply to MikeTeske)
Post #: 2
RE: v_GS_COMPUTER_SYSTEM / Computer_System_DATA has mor... - 11/13/2008 4:21:02 PM   
MikeTeske

 

Posts: 3
Score: 0
Joined: 11/13/2008
Status: offline
Thanks jnelson993,

I have been using analytics in Oracle for quite a while and thought of that but did not pursue it.  Most of our SQL Server stuff is 2000 and was not aware that 2005 had this feature.  Since our Config manager is running on 2005, I might use this.

However I would like to know if I have a data problem, or is there a better way to get my data.  I started tossing the idea of max(TimeStamp) as a guess.  Still not sure if this is the right way to do it, not questioning the "analytics" versus "group by inline view", just is using the max TimeStamp the right way.

Mike

(in reply to jnelson993)
Post #: 3
RE: v_GS_COMPUTER_SYSTEM / Computer_System_DATA has mor... - 11/13/2008 4:55:57 PM   
jnelson993


Posts: 959
Score: 132
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
Ah, another Oracle guy!  I'm a former Oracle guy myself :)  Analytics in the Microsoft SQL world actually refers to Business Intelligence/Data Mining, just so you know.  That might throw some MS-centric folks off. 

But yes, SQL 2005 has the ability to do row numbering and ranking, and dense ranking and NTILE.

I don't know if you have a data problem or not, if you do, we have it to.  I see like 20 machines with this problem, but out of 200K machines, 20 machines is nothing.  I have more chunks of corn in my...uh...nevermind.

But if you WANT to go aggregate to handle SQL 2000 you can.  It's just less techsexy.  There you'd just make a derived table that has all of the MAX(TimeStamp) values for v_GS_Computer_System and then join back to v_GS-Computer_System on the resourceID and the timestamp so it only pulls the rest of the row for that timestamp. 

Is this making any sense?
--SQL 2000 capable version
SELECT
  wss.LastHWScan,
  cs.Name0,
  cs.Manufacturer0,
  cs.Model0
FROM
(SELECT
     ResourceID,
     MAX(TimeStamp) AS TimeStamp
  FROM  
     dbo.v_GS_COMPUTER_SYSTEM
  GROUP BY
     ResourceID) AS Maxes
  INNER JOIN dbo.v_GS_COMPUTER_SYSTEM AS cs
     ON cs.resourceID = Maxes.resourceID
    AND cs.TimeStamp = Maxes.TimeStamp
  INNER JOIN dbo.v_GS_Workstation_Status AS wss
     ON cs.ResourceID = wss.ResourceID
WHERE
  wss.LastHWScan > getdate() - 10







_____________________________

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

(in reply to MikeTeske)
Post #: 4
RE: v_GS_COMPUTER_SYSTEM / Computer_System_DATA has mor... - 11/13/2008 4:58:22 PM   
jnelson993


Posts: 959
Score: 132
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
Oooh, it's even got marginally lower in cost this way.

_____________________________

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

(in reply to jnelson993)
Post #: 5
RE: v_GS_COMPUTER_SYSTEM / Computer_System_DATA has mor... - 11/13/2008 5:24:01 PM   
MikeTeske

 

Posts: 3
Score: 0
Joined: 11/13/2008
Status: offline
Thanks,  the sql stuff makes perfect sense.

Still trying to validate that using the record with the most recent time stamp is the right approach

Nice to see others have more than one row in v_GS_COMPUTER_SYSTEM per machineid.
I guess I should not be surprised, since the pk is MachineID,InstanceKey.
 
Going off to get the Manufacturer and Make should be a simple join. I wonder how many other queries out there have this risk, however small it might be.
 
I caught this problem in another script, where I create a list of worstations and insert them into an asset managment database, the script stops because it thinks I am trying to create duplicate assets. 
 
 
 
 


(in reply to jnelson993)
Post #: 6
RE: v_GS_COMPUTER_SYSTEM / Computer_System_DATA has mor... - 11/13/2008 5:42:08 PM   
jnelson993


Posts: 959
Score: 132
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
I know I've also seen this problem on v_GS_Operating_System.

_____________________________

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

(in reply to MikeTeske)
Post #: 7
Page:   [1]
All Forums >> [Management Products] >> System Center Products >> System Center Configuration Manager >> v_GS_COMPUTER_SYSTEM / Computer_System_DATA has more than one row per machine. 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.266