How to achieve E-mail alerting when an SQL toolkit returns 0 rows

We had an interesting problem on a recent ticket where a client has a normal rule that alerts via E-mail when an SQL toolkit returns no rows. In this case its on an SQL toolkit sampler that has a set of views that will run in parallel. The problem is that when the data is initialized it reports rowsReturned = 0 despite the query not yet running. The time between the data view comes into existence and the SQL completing is an unknown. Any use of a delay in the rule will apply to all runs of that rule, even in normal operation which is not appropriate.

I was able to achieve what the client wanted by using an expected row in the sampler configuration.

I added an 'Expect row' in the advanced configuration, meaning that when the data view is first created there is a row present with just one column (availability). the cell value is 'absent', but this is not so interesting. What IS important is that the columns that will be returned as a result of the SQL query is are not present, and will not be present until it has completed.

Because of this last point we can now write a rule that looks for one or more of the columns we expect to be present post run of the SQL, and where the row count is 0. The expected row itself if NOT counted in the rowsReturned value, so we can still test for the 0 condition.