Query to Output a CSV or Excel like file

spectrolab

Registered User.
Local time
Tomorrow, 00:57
Joined
Feb 9, 2005
Messages
119
Hi Guys,

I have 2 tables

tblXRFResults

ResultID
SampleName
Date
SampleDate
a few others not necessary in this

and tblXRFResultsConcentration

ResultID (many records linked to 1 record in tblXRFResults)
Concentration
CompoundName

What I need to set up is a query that will allow me to generate a report that will give an excel like format, with the column headings being the SampleName, followed by the CompoundName(s) from the other table and the "rows" will be corresponding sample name and concentrations.
I am sure this is pretty easy, but I am stumped!

Any help would be greatly appreciated.
 
SELECT R.SampleName, C.CompoundName, C.Concentration AS Concentrations
FROM tblXRFResults R
INNER JOIN tblXRFResultsConcentration C ON R.ResultsID = C.ResultsID

Then base a report off of this.
Basically, if I understand correctly
 
Thanks for the reply, but basically I am pretty stupid when it comes to SQL. Where do I put this? In the actual query criteria?
 
That would be the whole SQL with an added semicolon (;) at the end.
 
Thanks for the help

Thanks FoFa, but I don't think I explained it properly in the first place. What I currently have is a query that matches the resultID to the SampleName from another table, in the table XRFResultsConcentration there are 12 or so records with this ResultID and a CompoundName (Fe, Si, Ca, TiO2 etc) and a concentration (67.5, 2.5 etc) What I need to do is make a report that looks like this:

Sample Name Fe Si CaO Ti etc
Sample1 67.5 2.5 1.4 0.05
Sample2 64.1 2.1 1.2 0.04

Is this something that is easy to do? I tried using dlookup with VBA and ended up confusing myself.
As you can see, the CompoundName needs to be a column heading, it isn't in the table
Any help would be greatly appreciated
 
spectrolab, you need to follow the footsteps of Julius Caesar. Divide and conquer. Working backwards, you can export a table OR A QUERY to a spreadsheet from the Analyze it with Excel icon that is on the toolbar. So the next trick is to get the query that contains what you want.

This next part is where life gets trickier. You were correct to build a many to one table with the parts you wanted per sample. But now you want to denormalize the child table - and you can't do that with SQL. At least, not very easily.

I sometimes give oddball advice because I was never inside the box in order to have to think outside of it. Why did you bother to use Access for this beast when it seems that (from your description of the goal) Excel would have been a better place to start? Don't get me wrong, Access is great at what it does, but your description cries out for a spreadsheet. Which Access ain't.

Unless you have some other specific things that you want done via Access, I would not bother using it here. A tabular display of sample vs. concentrations of the components is a hard thing to do with Access.

Now, I can go WAY outside the box here and tell you to denormalize the table in a very highly specific way - but depending on the number of components you will have in your samples, it wouldn't take long to break Access on its limits. Here is my thought, but I'm also going to preface the explanation by saying that it works best ONLY if the possible components that can be in the same are strictly limited and do not change over time.

If you had a table that was
Sample#,PK, integer (or whatever your format requires)
ConcFe, single, concentration of iron
ConcSi, single, concentration of silicon
ConcCaO, single, concentration of calcium oxide
...

then you can do this very easily.

Yes, I know that it appears to violate normalization. Except maybe it doesn't. If the list of possible components is relatively small (<20 possible compounds or elements) and relatively invariant,then these values are just sample attributes in a sample table. This isn't totally denormalized because the sample number is still rightfully the prime key and the values of the individual fields depend on that prime key. So there is an ARGUMENT that this isn't totally denormalized.

If you shoot for the wide-open, any-compound-is-possible analysis, then this doesn't work because the range and variety of compounds will quickly swamp the ability of Access to do what you want.

If you don't like VBA and if there is no overriding reason to use Access here, then this isn't an Access problem, it is an Excel problem based on what it would take to solve it the easiest way.
 
Thanks Doc,

The reason it is this format currently is I am using something posted on here by JoeCruse and Wayne Ryan et al to auto import a result file spat out by a spectrometer. The table looks good and the import works fine, but how do I work with the data? I could report each result individually, but, most of my clients submit hundreds of samples and would like a nice easy to read report that they can do data manipulation on in a CSV or Excel format. Hence my need for this solution. The only option I have come up with so far is to do a query for each analyte (eg Fe result, Si result etc) and using each query in the report. Not ideal, but i am ironing out the bugs at the moment. I agree, and excel spreadsheet is probably the way to go, but, I already have the data in the table in this format.
In previous incarnations of this I have had a flat db structure where all the results were sent in batches and looked very much excel like, it may have to be resurrected.

Nigel
 

Users who are viewing this thread

Back
Top Bottom