Can you try something like this:
Code:
Select A.Location, A.CollectionDate, B.Analyte, Coalesce(T.Results, 'n/a') As Results
From (
Select Location, CollectionDate
From YourTableName
Group By Location, CollectionDate
) As A
Cross Join (
Select Distinct Analyte From YourTableName
) As B
Left Join YourTableName T
On A.Location = T.Location
And A.CollectionDate = T.CollectionDate
And B.Analyte = T.Analyte
Order By A.Location, A.CollectionDate, B.Analyte
Your results will come back like this:
[tt][blue]
Location CollectionDate Analyte Results
-------- -------------- -------- -------
Well-1 2008-01-01 Arsenic <.01
Well-1 2008-01-01 Copper n/a
Well-1 2008-01-01 Lead n/a
Well-1 2008-02-01 Arsenic <.01
Well-1 2008-02-01 Copper n/a
Well-1 2008-02-01 Lead n/a
Well-2 2008-01-01 Arsenic n/a
Well-2 2008-01-01 Copper n/a
Well-2 2008-01-01 Lead <.01
Well-3 2008-01-01 Arsenic n/a
Well-3 2008-01-01 Copper <.01
Well-3 2008-01-01 Lead n/a
[/blue][/tt]
Then, when you are displaying your results, keep track of the location and collection date. When they change (from one row to the next) create another column in your report. Alternatively, you can check the number of distinct analytes. This result set will always have a multiple of them. So, if you know there are 3 analytes, then every 3rd row should start a new column.
The benefit here is that you have just a single query to get all your data and relatively simple logic for pulling it out of the result set.
Let me know if this will work for you.
-George
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom