1

I try to do a search on a MSSQL 2005 Express server where our WSUS database is installed. I'd like to get filenames and digest values for the current revision of sepcific updates. This is the query I'd like to run:

SELECT 
    * 
FROM 
    tbRevision as rev 
    join tbLocalizedPropertyForRevision as lpfr on lpfr.RevisionID = rev.RevisionID
    join tbLocalizedProperty as lp on lp.LocalizedPropertyID = lpfr.LocalizedPropertyID
    join tbFileForRevision as ffr on rev.RevisionID = ffr.RevisionID
WHERE 
    lpfr.LanguageID = 1033 and
    rev.IsLatestRevision = 1 and
    rev.IsBeta = 0 and
    lp.Title like '%931125%';

The problem is that this query will find nothing though there are revisions with that KB number in them. If I remove the last join line join tbFileForRevision as ffr on rev.RevisionID = ffr.RevisionID from the query I get all results back.

Wondering what was wrong I started a new query from the other side, knowing already the filename:

SELECT
    *   
FROM 
    tbLocalizedPropertyForRevision as lpfr
    join tbRevision as r on r.RevisionID = lpfr.RevisionID
    join tbFileForRevision as ffr on ffr.RevisionID = r.RevisionID
    join tbFile as f on f.FileDigest = ffr.FileDigest   
    join tbLocalizedProperty as lp on lp.LocalizedPropertyID = lpfr.LocalizedPropertyID
WHERE
    f.FileName like '%rootsupd%'

In this resultset the field Title is always "Binary 0" and the Description and ReleaseNotes are always filled with NULL, though the LocalizedPropertyID is filled correctly and matches the other LocalizedPropertyID from tbLocalizedPropertyForRevisiontbLocalizedPropertyForRevision

Is my query so off? What did I do wrong? If you need more details on the schema I'm happy to provide them.

EDIT: Link to the SUSDB Diagram If you need it in another format, tell me how to provide it. Many companies using Microsoft Software have a WSUS, maybe you can access that server yourself.

1
  • please provide the table schemas and the result required. It might be possible that the inner joins you have added needs to be corrected.
    – Deepshikha
    Feb 13, 2014 at 15:24

1 Answer 1

1

When debugging multi-join queries where most of the tables are part of the WHERE clause, it helps me to break the query into parts that I can test individually, like so:

SELECT * 
FROM 
    tbRevision as rev 
    left join (
        select *
        from tbLocalizedPropertyForRevision as lpfr
        where lpfr.LanguageID = 1033 
    ) as lpfr 
        on lpfr.RevisionID = rev.RevisionID
    left join (
        select *
        from tbLocalizedProperty as lp
        where lp.Title like '%931125%'
    ) as lp 
        on lp.LocalizedPropertyID = lpfr.LocalizedPropertyID
    left join (
        select *
        from tbFileForRevision
    ) as ffr 
        on rev.RevisionID = ffr.RevisionID
WHERE 
    rev.IsLatestRevision = 1 and
    rev.IsBeta = 0

Running the above would give me all the records matching the rev table criteria. (The left joins insure that I get everything.)

Then I could change the join to lpfr back to an inner join and see how many records I get.

Then I would change that join back to left join and add to the WHERE clause at the very bottom:

and lpfr.LanguageID = Is Null

to show me what is missing that I might not want to be missing.

The beauty of this approach is that you can highlight a particular code block:

    select *
    from tbLocalizedPropertyForRevision as lpfr
    where lpfr.LanguageID = 1033 

plus whatever other temporary debugging criteria you can think of, and run it in isolation to see what records you get back.

Once you find your problem, you can restore your query to the original form, with inner joins as you obviously require in this case, for deployment to your app.

As you are more familiar with your schemas and data than we are, this kind of methodical analysis will probably help you get your answer faster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.