views:

38

answers:

1

Hello,

I am joining against a view, in a stored procedure to try and return a record.

In one table I have something like this:

Measurement | MeasurementType | Date Performed

I need to plot TireHeight and TireWidth.

So I am flattening that table into one row.

I only want to return a row though if both TireHeight and TireWidth were measured on that date. I am not using the date performed for anything other than joining TireWidth and TireHeight together. I run a calculation on these 2 numbers for my chart point, and use TireAge for the other axis.

How can I exclude a result row if either TireHeight or TireWidth are not available?

Thanks!

+3  A: 

You'd use an INNER JOIN to only return rows when they are present in both tables. For example:

SELECT   th.DatePerformed
,        th.Measurement as TireHeight
,        tw.Measurement as TireWidth
FROM (
    SELECT DatePerformed, Measurement
    FROM   Measurements
    WHERE  MeasurementType = 'TireHeight'
) th
INNER JOIN (
    SELECT DatePerformed, Measurement
    FROM   Measurements
    WHERE  MeasurementType = 'TireWidth'
) tw
ON tw.DatePerformed = th.DatePerformed
Andomar