Query to work out reaction times

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339
Nice easy one to start with....

Just wondered if this was possible or whether I need to adjust the set-up of my tables. I'm trying to work out the time taken for a chemical reaction to finish. I have a main table (tReactors) linked one-to-many by BatchID to a samples table (tSamples). The main table stores details of the reaction batch, the samples table stores analytical details of samples taken during the reaction. Each sample has an identifier as to the reaction point where it was taken- I want to work out the time difference between the Start Gas Date and Time and the Reaction End Date and Time, but can't seem to get my query syntax right.

tReactors
BatchID (pk)
BatchNo
Date
Time
Material
Other Fields...

tSamples
SampleID (pk)
BatchID (fk)
Date
Time
ReactionPoint (lookup from tReactionPoints)
Analytical Fields


I've tried setting up a query containing BatchID (from tReactors), Date, Time (both from tSamples) and ReactionPoint (restricted to show only the Start Gas and Reaction End points) but can't work out (other than doing query after query) how to get the time difference between them. The following three queries give me what I want, but I'm sure there's a more efficient one-step query which is what I'm after (ReactionPoint=8 is Reaction End, ReactionPoint = 6 is Start Gas):-

Query2

SQL:
SELECT [tSamples]![Date]+[tSamples]![Time] AS Expr1, tReactors.BatchNo
FROM tReactors INNER JOIN tSamples ON tReactors.BatchID = tSamples.BatchID
WHERE (((tSamples.ReactionPoint)=8));

Query3

SQL:
SELECT tSamples!Date+tSamples!Time AS Expr2, tReactors.BatchNo
FROM tReactors INNER JOIN tSamples ON tReactors.BatchID=tSamples.BatchID
WHERE (((tSamples.ReactionPoint)=6));

Query4

SQL:
SELECT (Query2!Expr1-Query3!Expr2)*24 AS BatchLength, Query3.BatchNo
FROM Query2 INNER JOIN (Query3 INNER JOIN tReactors ON Query3.BatchNo = tReactors.BatchNo) ON Query2.BatchNo = tReactors.BatchNo;
 
Last edited by a moderator:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Got it :biggrin:. I had to add a copy of the tSamples table, and use inner left joins on both. This is the SQL view if anyone's interested (or still awake):-

SQL:
SELECT tReactors.BatchNo, tSamples!sDate+tSamples!sTime AS Start, tSamples_1!sDate+tSamples_1!sTime AS [End], ([End]-[Start])*24 AS BatchLength
FROM (tReactors LEFT JOIN tSamples AS tSamples_1 ON tReactors.BatchID = tSamples_1.BatchID) LEFT JOIN tSamples ON tReactors.BatchID = tSamples.BatchID
WHERE ((([tSamples]![ReactionPoint])=6) AND (([tSamples_1]![ReactionPoint])=8));
 
Last edited by a moderator:
Upvote 0
Solution

Forum statistics

Threads
1,216,744
Messages
6,132,469
Members
449,729
Latest member
davelevnt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top