0

I have three tables. The TestOptionsTable contains a list of tests to be performed on an instrument.

The second table CreateScript, is a table to store scripts to run during testing. These scripts contain a selection of some of the tests stored in TestOptionsTable. The scripts are run and the tests appear on screen one by one.

The results of each test are entered on screen and stored in TestResultsTable. When saved, the column IsTestComplete, is marked with a 1 and has a datatype of BIT.

During a script being run, the user may be interrupted and some individual tests may not yet be carried out. When the tests resume I want to display a list of tests from a script that have yet to be completed. Essentially select data from TestOptions and CreateScript if there is no entry for that Test in the results Table. So far I have this but is not returning anything:

select TestType,TestName, Limits 
FROM CreateScriptTable 
inner join TestOptionsTable on CreateScriptTable.TestName = TestOptionsTable.TestName 
inner join TestResultsTable on CreateScriptTable.TestName = TestResultsTable.TestName
WHERE CreateScriptTable.InstrumentType= 'Instrument1' 
AND TestResultsTable.IsTestComplete <> 1
ORDER BY [Index] ASC, TestName

The idea is that data is returned if the IsTestComplete Column has not been set to true in the results table but no data is returned. Has anyone any ideas? Thanks!

EDIT: Expected output is something like below. With test Name, category and limits of test

Full Test 1     Visual              10  12
test1           Visual              0.1 0.22
Test 34         Visual              121 2222
Flow Test       As Found            1   1.2
Test 2          As Found            1   1.1
Test 3          As Left             85  105
Test 6          As Left             95  103

Any incomplete tests will not be in the Test Results Table. I would like to select from CreateScript any tests that are not in the results table.

4

1 回答 1

1

You say

Any tests that are incomplete will not be present at all in the Results Table.

this means that you cannot use a INNER JOIN to relate the two first tables with the results.
Probably you should rewrite your query with a LEFT JOIN like this

select TestType,TestName, Limits 
FROM CreateScriptTable 
inner join TestOptionsTable on CreateScriptTable.TestName = TestOptionsTable.TestName 
left join TestResultsTable on CreateScriptTable.TestName = TestResultsTable.TestName
WHERE CreateScriptTable.InstrumentType= 'Instrument1' 
AND TestResultsTable.IsTestComplete IS NULL
ORDER BY [Index] ASC, TestName
于 2013-01-02T11:32:10.773 回答