Test case reporting in Rational TestManager

Today I decided to boldly go where I have avoided going for the last six years. I finally started querying the Rational TestManager database. Mostly so I don't forget what I did, I thought I would share my attempt with the world.

I used the RATL_RT_TestManagementDatastore ODBC configuration (set up when you install the tools) and WinSQL.

The problem I wanted to solve was to get test case results for a given test plan. If you use TestManager, you can get results based on build folders, but if your test case results are in multiple folders, the results are aggregated and duplicates are added in multiple times. This makes the resulting numbers not quite worthless for large projects, but close...

This query returns the most recent test results for each test case within the test plan:
select
RESULT1.RecordedCaseName,
ITERATION1.Name,
RESULT1.ActualResultText,
LOG1.ModificationDate
from
TMS.CaseResult RESULT1,
TMS.Log LOG1,
TMS.TestCase CASE1,
TMS.Iteration ITERATION1,
TMS.Case_Iterations CASE_ITER1
where
CASE1.TestPlan = '11a1e288-f078-4082-b97e88a4b21e8454'
and RESULT1.TestCase = CASE1.UID
and CASE1.UID = CASE_ITER1.UID
and CASE_ITER1.IterationUID = ITERATION1.UID
and RESULT1.Log = LOG1.UID
and RESULT1.Promoted = 1
and (
ITERATION1.Name = 'R2_0 PLIQ WRS Auto'
or
ITERATION1.Name = 'R2_0 PLIQ WRS HUP')
and LOG1.ModificationDate = (select
Max(LOG2.ModificationDate)
from
TMS.CaseResult RESULT2,
TMS.Log LOG2,
TMS.TestCase CASE2,
where
CASE2.TestPlan = CASE1.TestPlan
and RESULT2.TestCase = CASE2.UID
and RESULT2.RecordedCaseName = RESULT1.RecordedCaseName
and RESULT2.Log = LOG2.UID
and RESULT2.Promoted = 1)

In the query above, '11a1e288-f078-4082-b97e88a4b21e8454' is the UID for the Test Plan from the TMS.TestPlan table. I'm not a SQL guy, so there may be a better way. If you know one, or have other queries you use, please share!