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:


  


Getting NULL values to display (not just a LEFT JOIN though!)

 
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 >> Getting NULL values to display (not just a LEFT JOIN though!) Page: [1]
Login
Message << Older Topic   Newer Topic >>
Getting NULL values to display (not just a LEFT JOIN th... - 11/13/2008 8:52:12 AM   
rlauder


Posts: 82
Score: 0
Joined: 11/27/2002
From: London, England
Status: offline
I'm trying to get a query together that will show information about specific files on our devices - particularly where the file exists in a directory that is shared out. To that end, we've enabled the Win32_Share class within the basic SMS_DEF.mof to get Share information added to our SMS Inventory database. So far, so good.

The query I have below will happily show file path and share information for files that exist in a directory that is shared. The trouble is that I want the query to show ALL files with their paths, but with a "NULL" value against the share name when the path is not shared out. i.e. when there is no entry in the v_gs_share table for the path in question.

===============
select sys.name0, sys.user_name0, inv.filename, inv.filesize, inv.modifieddate, inv.filepath, shr.name0, inv.filemodifieddate
from v_r_system sys inner join v_gs_softwarefile inv on sys.resourceid = inv.resourceid
inner  join v_gs_share shr on sys.resourceid = shr.resourceid
where sys.name0 like 'xxx%' and inv.filename  like '%.mp3'
and inv.filepath like shr.path0 + '[ \]'
order by sys.name0
===============

Whilst my SQL knowledge is improving all the time, I've spent several hours trying to figure this one out without success. I'd be very grateful for any pointers from the experts out there!
Post #: 1
RE: Getting NULL values to display (not just a LEFT JOI... - 11/13/2008 11:11:29 AM   
jnelson993


Posts: 959
Score: 132
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
Well, a couple of points. 

Yes, you do need the LEFT JOIN to accomplish that, but you also need to know that when you have a filter predicate for a left-joined table/view in your WHERE clause, it makes the query act like an INNER JOIN.  --> READ THIS <-- for more information. That's likely where you were getting hung up.  So really, the filter predicates need to go up into the FROM clause to make that work right.  What you're trying to accomplish is to show the v_GS_Share records where the filepath is like the filepath for the MP3 records (the way I understand it) of the v_GS_SoftwareFile.

Second, do you want it to show ALL files, or you want it to show all MP3 files?  Cuz you're filtering on .mp3 files currently, but you said "The trouble is that I want the query to show ALL files with their paths..."  Just making sure you're not expecting all files to show up when you filter for MP3.

Now, I don't have v_GS_Share in my environment, so I don't quite understand what you're doing with that "shr.path0 + '[ \]' but I'm going to assume you know what you're doing...the bracket operator [ ] is a special wildcard in SQL --> READ THIS <-- if for more information about the bracket wildcard.

So, having said all that, and again, not having the view to test in my environment, I'd do something like this:

SELECT  
  sys.name0,
  sys.user_name0,
  inv.filename,
  inv.filesize,
  inv.modifieddate,
  inv.filepath,
  shr.name0,
  inv.filemodifieddate
FROM    
  v_r_system sys
  INNER JOIN v_gs_softwarefile inv
    ON sys.resourceid = inv.resourceid
    AND inv.filename LIKE '%.mp3'
  LEFT JOIN v_gs_share shr
    ON inv.resourceid = shr.resourceid
    AND inv.filepath LIKE shr.path0 + '[ \]'
WHERE    sys.name0 LIKE 'xxx%'
ORDER BY sys.name0


  1. The first red line would make sure v_GS_SoftwareFile is only pulling MP3 records
  2. The INNER JOIN is changed to a left join so you get your NULL records
  3. V_GS_Share is now joining to v_GS_SoftwareFile instead of to SYS to make sure we only get records that match the share records on machines with mp3s. That might not be necessary, but it's a little extra measure.  If I had data I'd test it.
  4. The last red line would make sure v_GS_Share join only returns records when the software file path is the share path plus a space or a backslash (again, assuming you know that you're using a bracket wildcard)
Make any sense?


_____________________________

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

(in reply to rlauder)
Post #: 2
RE: Getting NULL values to display (not just a LEFT JOI... - 11/17/2008 11:42:51 AM   
rlauder


Posts: 82
Score: 0
Joined: 11/27/2002
From: London, England
Status: offline
Once again John - I owe you. Spot on!

Yes - I wanted to show all *.mp3 as per the criteria but previously most files were not being shown because they were in a directory that wasn't being shared out.

The bracket wildcard was because the v_gs_share table stores the share path inconsistently. If the root is shared out, the path has a "\" (e.g. "E:\"), but if the directory is further down the tree, it doesn't (e.g. D:\PACKAGESID"). I guess it's just a little tweak by MS to keep us on our toes...


(in reply to jnelson993)
Post #: 3
RE: Getting NULL values to display (not just a LEFT JOI... - 11/17/2008 12:00:54 PM   
jnelson993


Posts: 959
Score: 132
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
Hmm, well, I don't believe the way it's written will give you those records from down the tree where there's no trailing backslash...cuz what that wildcard is looking for is a trailing backslash, or a trailing SPACE, but not records where the last character is a letter with no trailing backslash...

And actually, it doesn't make sense.  SMS always puts a trailing backslash on the last character of the path, you shouldn't have anything else.  So run this query and tell me what it says:  It should only have 1 row with a backslash "\" in it.  If there are more than one rows then something's afoot.

SELECT DISTINCT
  RIGHT(fp.FilePath,1)
FROM  
  SoftwareFilePath AS fp


_____________________________

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

(in reply to rlauder)
Post #: 4
RE: Getting NULL values to display (not just a LEFT JOI... - 11/18/2008 10:38:25 AM   
rlauder


Posts: 82
Score: 0
Joined: 11/27/2002
From: London, England
Status: offline
You're right John - for the SoftwareFilePath table. The problem lies with the way that paths are collected by the Win32_Share class. If I do your query on v_GS_Share (the view created when Win32_Share data is collected by SMS once enabled in the base SMS_Def.mof), I get 40 characters returned - including "\" & NULL.

I take your point that my bracket wildcard might be looking for a file path of "D:\ " instead of "D:\" and would therefore risk missing a bunch of stuff. The missing "\" only applies to share paths at the root. In reality, I doubt if anyone has dumped mp3 files in the root of their machine - but, hey, there's always a first time...

(in reply to jnelson993)
Post #: 5
RE: Getting NULL values to display (not just a LEFT JOI... - 11/18/2008 2:21:15 PM   
jnelson993


Posts: 959
Score: 132
Joined: 2/18/2005
From: Minneapolis, MN
Status: offline
Oh, I get ya.

No, what I was trying to say is your bracket wildcard is looking for the last character of "\" or " " <--space.  For example:

"c:\Path"

Ends with an "h", which is not a backslash or a space so it won't match and won't get counted. Though,

"c:\Path\"
or
"c:\Path "

would match because of the trailing backslash or trailing space..although I'm not sure you can have a trailing space in a filename...I dunno.




_____________________________

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

(in reply to rlauder)
Post #: 6
Page:   [1]
All Forums >> [Management Products] >> Microsoft Systems Management Server >> Web Reporting >> Getting NULL values to display (not just a LEFT JOIN though!) 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.297